A Case for Static Typing

Wiktor Czajkowski
Nov 6 · 2 min read

Our programs don’t operate on the real world. They operate on a virtual, fictional world. One of the ways to make them work well is to make sure that this fictional world matches the real world, which can be done by modelling it explicitly.

Representation of the world

In programs we don’t manipulate actual, real entities. What we actually manipulate are bits in memory of our computer. However, those bits represent something. The crucial part, at least if we’re building a program to help us in some real-world task, is for that something to match the reality. An obvious example of that is a simulation. A slightly less obvious example of that is any business application. If the program helps you do something in the real world, you better make sure it has an accurate representation of that world.

Of course, this doesn’t count when you’re actually creating a fictional world that doesn’t match our reality. Like a game with 4 dimensions of space.

This idea of creating worlds interests me greatly, but that’s probably a thing for another piece.

Algebra is about models

One of the things I got through in my life was elementary school. Of course, in elementary school there is math. Looking back it’s actually great, but the way it’s taught leaves a lot of room for improvement.

In elementary and later schools I was kind of good at math. One of the best in the classroom, but not so much to win any competition or anything. I was just kinda getting most of the things that were taught. However, I felt a huge disconnect between what I was learning and basically everything else. Math was a thing for nerds, and I kinda identified as a nerd (still do), so it seemed like a good thing to be good at.

Some time later, I have discovered that all of the abstract mathematical concepts are based in the reality around us. Moreover, most of math, and science for that matter, is an attempt to describe our reality in precise terms. What I discovered very recently is that algebra is one of the languages those terms are built upon.

So, when a scientific discovery is made we write it down in this very specific language. Now if we are able to put some rules of the world in form of those algebraic symbols, we can also manipulate those symbols using rules of algebra!

This is very very very close to what we’re actually doing with programs. Once we are able to describe some real world entity or phenomenon with data structures, we can manipulate that description using a language. A programming language.

This is my understanding of the purpose of static typing — to create the rules of the “small universes” our programs are going to operate within. And to make it explicit, so we can verify they match the rules of the real world.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade