Martin Fowler writes about DynamicTypeCheck:
Recently some of our developers ran into the accusation that with a dynamic language like ruby you use so many dynamic type checks that you end up effectively writing your own type system. So they thought, since we’ve written a lot of real ruby code – how often do we make dynamic type checks?
We define a dynamic type check as the use of the methods
This made me think about the use of
instanceof in Java. A pretty non-scientific investigation of an Open Source Java application (Vuze) showed:
Lines of code: 740257 (
find . -name '*.java' | xargs cat |wc -l)
instanceof: 1926 (
find . -name '*.java' | xargs cat| grep -c ' instanceof ')
So, there is actually more instanceof in this Java project than there are dynamic type checks in the anonymous Ruby projects used for the statistics presented by Martin Fowler. I certainly hope it wasn’t a Java developer that accused dynamic languages to use lots of dynamic type checks!