Thursday, June 19, 2014

The Safyness of Static Typing

Marcel Weiher:

That the compiler is capable of catching (some) bugs using static type checks is undeniably true. However, what is also obviously true is that not all bugs are type errors (for example, most of the 25 top software errors don’t look like type errors to me, and neither goto fail; nor Heartbleed look like type errors either, and neither do the top errors in my different projects), so having the type-checker give our programs a clean bill of health does not make them bug free, it eliminates a certain type or class of bugs.


[Robert Smallshire] talks about this some more in the talk titled The Unreasonable Effectiveness of Dynamic Typing, which I heartily recommend. However, this isn’t the only source, for example there was a study with the following title: An experiment about static and dynamic type systems: doubts about the positive impact of static type systems on development time (pdf), which found the following to be true in experiments: not only were development times significantly shorter on average with dynamically typed languages, so were debug times.

2 Comments RSS · Twitter

While I prefer dynamically typed languages overall, I think the main advantage static typing brings is not safety or development time. Instead, it's the fact that the computer knows more about what you're doing than with a dynamically typed language.

This gives you access to things like the ability to automatically refactor code. If you have a long-running project (say, decade+), you will inevitably run into situations where you want to refactor large parts of your code. Static typing helps a lot.

Refactoring is often mentioned, yet the first automatic refactoring tool, the Refactoring Browser, was created in Smalltalk

The lack of static typing information was something the authors were obviously aware of as a hurdle to overcome, but they believed, correctly, that they both could overcome it and that the other advantages of Smalltalk would outweigh this drawback.

I vaguely remember them commenting that in retrospect it turned out to be much less of a problem than they had anticipated.

Leave a Comment