Why I Miss Static Typing

December 1, 2006 ⋅ 2 Comments »

These days, it seems like most people feel they can be more productive in a dynamic language, like Python or Ruby. In general, I feel the same way, but sometimes I do miss static typing. What I specifically miss is being able to look at a method and have some clue what the parameters are.

Take this (totally contrived) example, in Python:

def reportEvent(dest, event):
    if dest.isStarted():

And similar code in Java:

void reportEvent(ErrorLog dest, Event event) {
    if (dest.isStarted()) {

When you look at the Java example, you immediately have a better idea what is going on. In my experience (having worked on a large Smalltalk project), you will lose a lot of time in a dynamic language trying to figure out code just like this. And Stephan Schmidt raised another good point that autocompletion is much more difficult in dynamically-typed languages.

I think there’s a way to get the best of both worlds, and I’m surprised I’ve never heard anyone mention it before. Whenever you run the application, the runtime could take note of the type of each parameter, and then later feed that information to the IDE. If you’ve run the method 1000 times and the parameter has been a String each time, then you can pretty safely say that the parameter is a String. If it’s a Dog half the time, and a Cat the other half, then the type is Animal.

I don’t see why this would be especially hard to implement. Yes, it would require a higher level of integration between the IDE and runtime than we are currently used to, but it seems like it could be a real time-saver.


  1. Dubroy.com/blog » On static and dynamic typing, and corn tortillas - January 8, 2007:

    [...] I looked at several different aspects of type systems, and analyzed them in terms of the Cognitive Dimensions of Notations framework. One of the issues I addressed was mentioned in the post Why I Miss Static Typing. [...]

  2. Type inference, static checkers and IDEs « Aran at Grad School - April 29, 2009:

    [...] I’ve discussed this with Patrick Dubroy and Zak Kincaid, and we agree: A better way would be to have your IDE perform the analysis and make the information available live. I’m not sure how the information would be ideally presented (maybe as a tooltip, or as a specially marked insertion in the editing window) but it would be great to explore. [...]