RE: The Unreasonable Effectiveness of Dynamic Typing for Practical Programs

At my day job I work with JavaScript, but that’s not by choice, and I’m vocal about the advantages of modern static type systems that we forgo by choosing this language. A dissenting coworker directed me to this presentation by Robert Smallshire. I sympathize with Mr. Smallshire on the topic of science in the software industry; considering the amount of money that moves through this industry, we really ought to invest more in studying the efficacy of our methods. That said, he hasn’t convinced me of any fundamental failures of static typing.

The talk begins with a survey of some terms that you might hear in a programming language theory seminar: dependent types, existential types, phantom types, inferred types, algebraic types. Mr. Smallshire implies that these terms are unfamiliar to most developers, and he’s absolutely correct, but so what? New ideas don’t have to be familiar, and no professional programmer can ignore the state-of-the-art without risking obsolescence.

Later in the talk, Robin Milner’s A Theory of Type Polymorphism in Programming is dismissed with an out of context quote from the abstract: well-typed programs cannot “go wrong”. The audience presumably agrees that this is just not true, but of course it isn’t; in fact, it makes no sense in isolation, since we haven’t clarified what well-typed and program mean in this context. Milner’s paper makes this clear, and does not claim that your compiled C++ or Java program can never crash.

Around the 38 minute mark, some hard data is presented: the details of the study are missing, but the claim is that only 2% of issues with dynamically typed programs are in fact “type errors”. One table shows the Python TypeError as the source of 1.2% of all issues in github Python repositories. But this is meaningless: errors manifesting in a Python TypeError are a proper subset of the errors which could be eliminated by a modern static type system.

The highlight of the presentation comes around the 30 minute mark, where Mr. Smallshire claims to demonstrate an embarrassing failure of static type systems via that of F#. Check out this gist for a demonstration of how errors of this class can indeed be systematically eliminated, in this case using Haskell’s type system.