Thursday, February 14, 2008

Who's afraid of dynamic typing?

If you're afraid of dynamic typing, stop. Take some time to learn a good dynamically-typed language, then take some more time to learn how some people build big production systems with it, and how they manage to do it with less effort and increased safety and reliability vs. equivalent implementations in popular statically-typed languages. Regardless of your conclusions, I can guarantee you'll increase your breadth as a developer and that your new insights will improve your effectiveness in any programming language.

So why are people afraid of dynamic typing? Maybe it's the way most people approach dynamic languages:

  1. skim through some tutorials
  2. write some toy code
  3. reach a final verdict about their applicability to large-scale development
These verdicts are usually based on gut instinct and second-hand stories rather than on actual experience developing real systems with guidance on proper ways to use the language.

I'll finish with a story: One time a good C++ developer got excited about a dynamic language. He used it extensively for scripting and was familiar with all of its features, and he convinced the necessary parties to develop a real upcoming system in this language. But when writing the system he threw every one of his development practices out the window and half-assed the whole thing, writing incredible spaghetti code, not testing, and cramming in as many language features as he could. The project was not a complete failure, but the "obvious" conclusion was that this language wasn't appropriate for these tasks, whereas my conclusions are:

  1. Be responsible. You may also use a dynamic language for scripting, but when you're building a real system you're not scripting.
  2. Don't rely on static typing - it isn't there to rely on. You have to unit-test.
  3. Use your language's idioms and good shortcuts, avoid the evil ones. Seek experienced guidance on this issue.
  4. Don't get in over your head - before applying a language feature in production, become familiar with it. Don't worry, it'll wait for you!

Some articles I love on the topic:


  1. I agree on this point
    Dynamic languages have many benefits (ease of development, expressive statements), however when abused, they can be turned into a tool of evil.

  2. "a tool of evil" :p

    I've seen evil, and it is available in any language :)