Owen on software

Static Typing: Bad science & prejudice

07 September 2015 - Comments

Everyone who has ever done any software development in the Enterprise knows that statically typed programming languages are clearly better than dynamically typed languages. It’s just something we know. Except that, when you look into it, we have pretty much nothing to base that assertion on.

Prejudice and isms

I’ve recently been exploring Clojure, and the idea of using it in the Enterprise. Clojure is dynamically typed. That is a big stumbling block. This is because, every enterprise developer knows static typing is better than dynamic typing.

Of course, it’s a self-evident truth. Clearly, statically-typed programming languages are better. They offer an additional safety-net. We just know this. It’s not even something anyone in the Enterprise debates. It’s a given.

And yet …

The not-so self-evident truth

When you stop and honestly ask yourself what that opinion is based on, as I have, you have to face a quite uncomfortable truth. Because, the answer is not very much.

So sure, you can try and argue that it’s applied logic. Static typing provides more compile time checking and safe-guards. Thus, it is better. More is always better. And initially it sounds like a strong argument, until you think about it.

The argument might hold more water but for two important factors:

  1. Static typing comes at a cost.
  2. We don’t rely solely on the compile time checks that static typing provides.

In practice, we write tests, use IDEs, etc. So an important question is, what errors are those tools going to miss that static type checking is going to pick up, if any? I don’t have an answer. Looking around, it doesn’t seem anyone else does.

So you would think, that given it is such a strongly held position, there would be a lot of supporting evidence for static typing and the productivity and correctness it brings to software development. That brings me to …

Bad science

Dan Luu wrote an excellent, if rather lengthy, summarisation of recently papers on the subject: How Do Types Affect Productivity and Correctness? A Review. It’s definitely worth a read, if you can find the time.

It basically comes down to this. There are various papers with some fairly bold claims in favour of static typing. The trouble is when you dig into the papers there is a lot of bad/weak science1. Most of the papers themselves admit that their results cannot be generalized.

If you were hoping for some scientific studies to back up your strongly held views on static typing, well, you are going to be very disappointed. The data isn’t there. Not yet. That’s not to say it won’t be one day. But right now, today, you can’t make the case.

Tradition and anecdotes

We can always appeal to tradition though. Not all tradition is bad. Sometimes tradition is the realization of hard learnt lessons. On the other hand, sometimes tradition is little more than conjecture and ignorance.

Anecdotes are powerful. Sometimes they are compelling. Perhaps there was a project that was using a dynamically typed language. Perhaps it didn’t fair so well at scale. But life is complex. How do we know there weren’t some other confounding factors? Which is why we need science and solid data. Unfortunately, right now we don’t have any.

So what’s the answer?

I don’t know. I’m not sure anyone knows. Sure, we all have opinions. But can we justify them? I don’t think anyone, even Rich Hickey or Martin Odersky2, has enough solid evidence to settle this argument.

We need more studies, better science, more funding to explore issues like these.

In the meantime, maybe we need to be more open to using dynamically typed languages in the Enterprise.

  1. To be fair, conducting these studies is anything but easy. It’s a very complex problem domain. 

  2. That would be an awesome smackdown: Dynamic vs Static Typing featuring Rich Hickey and Martin Odersky. 

Tags: Clojure Ideas


comments powered by Disqus