Blog Home RSS Kelvin Jackson

On the other hand, a type system is nice to have

A while back, I wrote a post about how programming in a language without a static type system was not as difficult as I had expected. While I still stand by the highest-level interpretation of that assertion — Python, Clojure, and other languages without static typing are still very usable for many tasks — several more months of experience with Clojure has led me to rethink just how willing I am to live without static typing. In a sentence, if I am ever the creator of a programming language that other programmers are going to use, that language is going to have a static type system.

Type systems catch many, many common bugs, of which I have now encountered a great deal in my current Clojure project. I have spent many hours debugging issues that would simply never have occurred if our project has been written in Java, or if we had used a dialect of Clojure with required static typechecking (if that even exists). I have even occasionally written tests that do not actually test the functionality that I thought they were testing, because of incorrect assumptions I made that would have been immediately refuted by static type checking. In short, Clojure's extreme duck typing has cost me a considerable amount of time over the last year.

This, of course, is not an excuse for every language to become as wordy as Java or C#. Type inference makes it possible to cut down on the number of overt type annotations in the code, while preserving the benefits of static type checking; type annotations for primitive types can also be made short and easy to type. However, the benefits of having them cannot be understated.

This post, I suppose, is a subtle (or not so subtle) encouragement to web developers to migrate their existing JavaScript codebases over the TypeScript. It will only get more annoying to do the longer you wait, and you will start seeing improvements and time savings the moment you make the change.