Typing: Safety causes Bugs

8 PM February 6, 2003

Static vs Dynamic typing is a great source of controversy. Like many of the other great debates (e.g. where to put the curly braces) there is not a lot of factual support for either side. One notable exception is Lutz Prechelt’s paper "An empirical comparison of C, C++, Java, Perl, Python, Rexx, and Tcl".

The abstract reads:

80 implementations of the same set of requirements, created by 74 different programmers in various languages, are compared for several properties, such as run time, memory consumption, source text length, comment density, program structure, reliability, and the amount of effort required for writing them. The results indicate that, for the given programming problem, “scripting languages” (Perl, Python, Rexx, Tcl) are more productive than conventional languages. In terms of run time and memory consumption, they often turn out better than Java and not much worse than C or C++. In general, the differences between languages tend to be smaller than the typical differences due to different programmers within the same language.

Anyway, here is my opinion in a nutshell. Dynamically typed languages do lead to shorter programs. For example, where a Java programmer would typically write something like:


    ExpandedChoicePolicyOption expandedChoicePolicyOption 

            = new ExpandedChoicePolicyOption();    

a Python programmer would accomplish the same thing with:


    policyOption = ExpandedChoicePolicyOption()

assuming, of course, that they could be persuaded to write insurance applications. (The variable name in Python snippet is shorter on purpose - that's one noticeable differences between typical Java programs and typical Python programs.)

This leads me to the following logic:

  • The more typing the programming language has (for ‘safety’), the more typing the programmer does at the keyboard.

  • Longer programs result in more errors.

  • Conclusion: a feature justified by "safety" results in larger numbers of bugs.

Don’t ask me to back this up with fact. All I have is personal anecdote and conjecture. On the other hand, Lutz Prechelt does have some solid fact to contribute.

By alang | # | Comments (1)
(Posted to Software Development)
© 2003-2006 Alan Green