I can't take credit for this statement, since I am only drawing the logical conclusion from a statement said by a man far smarter than I.
Donald Knuth wrote in his famous paper Structured Programming with go to Statements (PDF):
We should forget about small efficiencies, say about 97% of the time: pre-mature optimization is the root of all evil
Since compilation is premature optimization, it is therefore, the root of all evil. Simple!
Static typing, weak typing, dynamic typing, strong typing, WTF?
There are a number of misconceptions concerning typing.
The meaning of weak and strong typing, is not clearly defined but is mostly interpreted like this.
In a weakly typed language, such as C, the types of the variables can be automatically converted from one representation to another, while in a strongly typed language an explict conversion is required.
This is not what I am writing about here. I am referring to static vs. dynamic typing and the definition I am using is:
- Static typing, the type checking is performed at compile-time.
- Dynamic typing, the type ckecking is performed at run-time.
Every time I build my code, my entire code base is type-checked. EVERY TIME! When I am working in development mode, I only care about the method and class that I am currently working on. As long as my tests pass I am happy, type-safe or not.
In development mode it is actually more accurate to call static typing pre-mature de-optimization than pre-mature optimization.
The only reason, to ever use static typing, is because the code may be optimized better, to give better performance.
So, the strategy should be:
- Use a dynamically typed language during development. It gives you faster feedback, turn-around time, and development speed.
- If you ever get lucky enough to have performance problems, which cannot be solved with caching or algorithmic optimization, rewrite the problematic code in a statically typed language.
This is what Twitter did, and it has worked well for them.
Proponents of Java often have the misconception that dynamically typed languages are unsafe, yet they use frameworks, like Spring, and Qi4J, that are littered with reflective code, and without the so-called safety net that static typing is believed to give. The reason these frameworks are popular is because they allow us to be more productive. The reason they are more productive is because they use dynamic programming techniques.
Anyone, who has worked seriously with a modern dynamically typed language like Ruby or Smalltalk, know that they are more productive. Working with waterfall languages after working with agile languages is just painful. (Thanks to Andreas Ronge for coining the term Waterfall Language.)