Skip navigation.

Martin Fowler on dynamic typing

Before the age of VB and before the coming of the World-Wide Web, I spent over 10 years programming full-time in static-typed languages such as C and C+. Nevertheless, I was extremely fond of playing around with dynamic languages back then - I still remember how mind-blowing HyperTalk (remember HyperCard?) was in 1987. And I was suitably impressed by how beautifully Perl processed strings when I started using it in the mid-90's. I even wrote a dynamic language modelled on HyperTalk in the early 90's for one of my employers.

Now both static and dynamically typed languages have their advantages, but given the speed of modern processors (they are now 1000 times faster than in 1990), the tide has turned and I feel it's pointless today to code in static-typed languages except for the most performance sensitive code (graphics subsystems, operating systems, compilers, interpreters).

As far as I can see, the last major objection to dynamically-typed lanaguages is the claim of better safety due to type-checking. I couldn't agree more with Martin Fowler, famous documenter of Enterprise best practices, when he praises dynamic typing and discusses the myth of type-safety. As he says:

I really began to question this when I got involved with some moderately sized Smalltalk projects. The general argument for static types is that it catches bugs that are otherwise hard to find. But I discovered that in the presence of SelfTestingCode, most bugs that static types would have were found just as easily by the tests. Since the tests found much more than type errors, you needed them in either a static or dynamically typed language, so having the static typing gave you little gain.

Also some dynamic languages such as Python impose type-safety checks after a variable is set for extra safety. PHP adopts a more liberal philosophy, types are happily converted for you in the background. This is ok if you are using PHP for string/HTML processing, but is something that you have to be aware of of you are using PHP in other domains.