Static versus Dynamic Typing


The trade-off that we've just witnessed between type safety and flexibility typifies the ongoing debate over language styles. On the one side are statically typed languages, such as C#, C++, and Java, which check types at compile time and emit compilation errors if the declared types aren't consistent. On the other hand, dynamically typed languages, such as Python, Ruby, Groovy, and Smalltalk, do their type checking at runtime. The compiler does not insist on type consistence; nor, indeed, does the syntax of these languages permit such checking.

As we saw in the FACTORY example, static typing can lead to dependency knots that force modifications to source files for the sole purpose of maintaining type consistency. In our case, we have to change the ShapeFactory interface whenever a new derivative of Shape is added. These changes can force rebuilds and redeployments that would otherwise be unecessary. We solved that problem when we relaxed type safety and depended on our unit tests to catch type errors; we gained the flexibility to add new derivatives of Shape without changing ShapeFactory.

Proponents of statically typed languages contend that the compile-time safety is worth the minor dependency issues, the increased rate of source code modification, and the increased rate of rebuild and redeployment. The other side argues that unit tests will find most of the problems that static typing would find and that the burden of source code modification, rebuild, and redeployment is therefore unecessary.

I find it interesting that the rise in popularity of dynamically typed languages is, so far tracking the rise in adoption of test-driven development (TTD). Perhaps programmers who adopt TDD are finding that it changes the safety versus flexibility equation. Perhaps those programmers are gradually becoming convinced that the flexibility of dynamically typed languages outweighs the benefits of static type checking.

Perhaps we are at the crest of popularity of the statically typed languages. If the current trend continues, we may find that the next major industrial language is more related to Smalltalk than to C++.




Agile Principles, Patterns, and Practices in C#
Agile Principles, Patterns, and Practices in C#
ISBN: 0131857258
EAN: 2147483647
Year: 2006
Pages: 272

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net