Fallacies in the Great Dynamic vs Static Debate

The debate between static typing and dynamic typing rages on and on. It polarises geeks in the same way that political distinctions such as “left wing” and “right wing” or “liberal” and “conservative” polarise mainstream opinion. (Incidentally, I really want to point out to American readers that “liberal” is never an insult, nor is it the opposite of “conservative”. Indeed, I consider myself to be both liberal and conservative. But I digress.)

Unfortunately, as with any debate which has any passion in it, a lot of well-worn old logical fallacies get rolled out. For example we see a lot of arguments based on the Biased Sample fallacy, which goes something like this:

  • Hitler was a teetotal vegetarian
  • Hitler was a bad person.
  • Therefore, teetotal vegetarians are bad people.

When used by a dynamic typing advocate, this fallacy often takes the form:

  • Java, C++ and C# are statically typed languages.
  • Java, C++ and C# have problems X, Y, and Z (this part can vary in the specifics e.g. verbose syntax, lack of closures, slow compilation, etc. but the pattern remains the same).
  • Therefore, statically types languages are bad.

Just as the set consisting of Hitler is not a good representative sample of teetotal vegetarians, the set consisting of Java, C++ and C# is not an unbiased sample of statically typed languages. Oh sure, they’re the most popular thanks to an unfortunate accident of history… but for one thing, none of these languages support type inference (except the bleeding edge, very latest edition of C#, to a limited extent).

It really is amazing just how much of the advocacy for dynamically typed languages boils down to: “In Java, I have to type too much.” The fact is, although the verbosity argument is a useful one against Java, it’s completely irrelevant in the larger debate of static versus dynamic typing. That’s because there exist some statically typed languages that already know what types all of your variable and functions have; one generally only needs to add the type declarations in order to document the code for other human beings. Of course, one can add documentation to Ruby or Python code as well to indicate that the first parameter of some method should be a String, and so on, but the difference with a language like Haskell is that the compiler will check whether the declarations are correct. To get the same checks in Ruby, we have to write unit tests… so have we saved ourselves any of the wear to our keyboards that Java induces?

Of course, verbosity is not the only argument against static typing, it’s just the most bogus. I plan to spend a couple of posts looking at the other arguments, and asking whether they really apply to statically typed languages in general, or just to those few statically typed languages that everybody loves to hate.