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:
- skim through some tutorials
- write some toy code
- reach a final verdict about their applicability to large-scale development
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:
- Be responsible. You may also use a dynamic language for scripting, but when you're building a real system you're not scripting.
- Don't rely on static typing - it isn't there to rely on. You have to unit-test.
- Use your language's idioms and good shortcuts, avoid the evil ones. Seek experienced guidance on this issue.
- 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:
- Python Is Not Java, by Phillip J. Eby. A great quote from it is:
"... if you've been using Java for a while and are new to Python, do not trust your instincts. Your instincts are tuned to Java, not Python."
- Java Is Not Python Either..., also by PJE
- Strong Typing vs. Strong Testing, by Bruce Eckel
I agree on this point
ReplyDeleteDynamic languages have many benefits (ease of development, expressive statements), however when abused, they can be turned into a tool of evil.
"a tool of evil" :p
ReplyDeleteI've seen evil, and it is available in any language :)