Static typing has its benefits. However, specifications are more useful than types. While types can be seen as weak/lightweight specifications, tests do a better job at capturing behavior (or input-output relation); hence, better specifications. Also, a good suite of tests usually can catch most of the bugs avoided by types and immensely ease refactoring effort. With TDD, it is easy to detect errors early and refactor code. I can vouch for all of this based on my recent experience with using TDD. Of course, as you mention, types can help avoid type specific tests in a dynamically typed setting. This does raise the question —how does the cost of testing weigh compare to the cost of static typing?

As for types serving as documentation, they serve as weak documentation, e.g., not all int values represent cents and dollars. I’d say appropriate var naming provides more information. Then, there is the risk of appealing to “code is the documentation” :)

While static typing is good and can be helpful, I doubt if it beats good practice (and at times the flexibility of dynamic typing). While I believe it complements good practice, I am curious about the extent of complement. Folks interested in this area might find this study of programming languages interesting — http://rayb.info/uploads/fse2014-lang_study.pdf

In the end, I’d rather want a typing system that is helpful and does not get in my way; something like gradual typing. For the JavaScript community, I wonder if the issues are more practice/discipline related than technique related.

Written by

Programming, experimenting, writing | Past: SWE, Researcher, Professor | Present: SWE

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store