Debunking some static typing myths.
Today I read an article about static typing, written some months back. I believe it is a very short-sighted article, and factually incorrect in several respects. However, I do encourage you to read it, so that you’ll better understand the fallacies it portrays.
The first myth is that “static typing requires extra typing.” Anyone who has used a language like OCaml or Standard ML knows this to be a blatantly incorrect statement. Such languages offer static typing, yet also offer type inference. So it is very rare that one must manually specify the type of a function argument, for instance. A developer will do just as little typing as when using Python or Ruby, but will get the numerous benefits of compile-time type checking.
The second myth is that when it comes to static typing, “people will want to work around it.” Developers who strive to work around static typing clearly do not understand how to use it to their best advantage. Often, attempts to work around static typing are caused by a lack of preparation. Although one will never know everything about the problem domain in which he or she is developing a software solution for, even a small amount of research and preparation will allow one to use static typing to its full advantage.
That article discussed several other issues, but on further investigation it becomes clear that they have little to nothing to do with static typing, are convoluted micro-examples that have no real-world relevance, or actually are irrelevant when using languages like SML or Haskell.
There was one other paragraph that I wanted to discuss: Have I ever written dynamically typed code that has run for two hours, only to return and find that it broke because of a typeo or a wrongly-used type? Yes. But in almost every case it could have been fixed by better unit tests. Besides, those few situations pale in comparison to the man-months saved in typing, digging through verbose code, and wrestling with the type system..
This is clearly the wrong attitude to take when developing software. There is no reason for a type-related error to ever occur at runtime, especially when such checking can be performed at compile-time (ie. static typing). Furthermore, the use of unit tests to detect typing errors is sloppy and senseless. You’re manually doing work that even a rudimentary compiler can do for you (and probably a lot better than you could, too). And it’s just laughable to think that writing verbose unit tests somehow requires less typing than using a statically-typed language that supports type inference.
February 10th, 2008 at 1:28 am
I usually stand more on the dynamic language side, but I have to agree with you about type inference and unit tests.
I think perhaps the main problem here is that most languages that use static typing use type systems that are incredibly feeble. And, they generally lack type inference.
Shame :(.