Monday, December 15, 2008

Dynamic Languages Replacing Static Ones?

A number of years ago, Uncle Bob (Robert C. Martin) wondered if dynamic languages would replace static languages for mainstream software development.

Here is a summary of an article he wrote in 2003 titled "Are Dynamic Languages Going to Replace Static Languages?":

For many years we've been using statically typed languages for the safety they offer. But now, as we all gradually adopt Test Driven Development, are we going to find that safety redundant? Will we therefore decide that the flexibility of dynamically typed languages is desirable?

The static languages being referred to by the article are typical mainstream static languages such as Java and C++ by the way, not languages like Haskell or Objective Caml.

When writing all code test-first with 100% test coverage for the implementation, one seriously begins to wonder if the static typing is helping or in fact hindering design flexibility in comparison to dynamic typing.

Here is a metaphor that may help us understand this better.

Static typing is like choreographing circus stunts with safety built into the moves. The circus people can only practice moves that are safe and would not result in them crashing down in front of the audience. While such moves will still look good due to the great practice put into them, they are generally conservative due to safety consciousness.

On the other hand, dynamic typing is like choreographing wild circus stunts, attempting such wild moves that if successful completely wow the audience.

Traditionally, performers would get into horrible accidents while practicing such wild moves, which is the reason why static typing became the norm in software development for a while. It was after all, the only way to achieve reliable business software delivery.

However, when the concept of a circus safety harness was introduced, performs were able to practice the wildest move and still be safe from injury. This is similar to having a unit-test suite acting as a safety harness for all the dynamically typed code you write. It lets you go wild with your software design, achieving unmatched productivity and flexibility with your code while remaining safely covered with your tests.

So, did test-driven development change the playing ground enough to enable developers to leverage dynamic languages in favor of static ones without the traditional fears that encouraged static typing in the first place?

5 comments:

Doug Schaefer said...

The question everyone needs to ask before answering this question, is why did BASIC fail? Dynamic languages don't scale. You can't build a large application using a dynamic language. Maybe we're reaching the point now that we have such good reusable components now that none of us are building large applications. I'm not sure we're there yet.

Andy Maleh said...

Here is a real-world example where a dynamic language scales to take advantage of a 64-core processor for financial processing:

http://syntatic.wordpress.com/2008/11/25/the-closet-jrubyists/

That project is greater in scale-ability requirements than most projects I've personally seen developed with static languages.

Ed Merks said...

I think some of these language trends are almost like fashion trends: they tend to be cyclical although you might not notice that until you're really old and jaded.

Unknown said...

Much of what you say is true. Although for me I make so many mistakes during programming that having to wait until I run a test to find the typo can also slow me down. (Not disagreeing that type-safety also slows you down).

But the big question is can you reliably get the Code-completion and solid refactoring tools for dynamic languages. I would really miss both... Especially good refactoring tools.

Neil Bartlett said...

There's a tendency amongst dynamic language fans to see static typing as a constraint... something that prevents you from doing what you really want to do.

I don't see it that way, instead I see static typing as an enhancer of my own meagre capabilities as a programmer. It allows me to write complex code that would simply be too difficult to keep track of if it were not typed.

Granted though, Java's type system is a really poor example of static typing. I'm really thinking of Haskell or Scala.

Indeed, this leads to another fallacy of dynamic language proponents: attacking Java as the exemplar of static typing when in fact it's one of the least representative. It's like attacking all dynamically typed languages based on the poor track record of BASIC.