24.2. Typing

One of the big debates concerning programming languages is strong (static, compile-time) versus weak (dynamic, run-time) typing. Much of the success of the so-called scripting languages is due to dynamic typing adopted by Perl, Python, Ruby, and the like. Code size, readability, speed of development, learning curve are all definite advantages of this approach. The drawbacks of dynamic typing are mainly in the areas of run-time speed, robustness (run-time type errors), and well-defined interfaces (components).

Most statically typed languages are explicitly typed in the sense that the developer has to tell the compiler which types to use. One of the difficulties is the handling of container types such as collections. If an explicitly typed language does not want to give up the main benefits (speed, rubustness, strongly-typed interfaces) of strong typing for container types, it has to offer parametrized types. That's why Java and C# had to eventually add generics (with Java not gaining the performance benefits, since its virtual machine does not support the generic types). Obviously, this complicates the languages significantly with C++ being the "best" example.

ML and Haskell offer a different solution: implicit typing using type inference. Here, the developer provides only the type information that can not be derived from the context. The compiler always chooses the most general type applicable. In a way, ML and Haskell make templates (generic types) the default, but without any of the hazzle required in an explicitly typed language such as C++.

It looks like the difference between strong and weak typing is getting more and more blurred. A good Lisp compiler is able to generate code that is almost as fast as C. Obviously, the ML and Haskell dialects also produce executables that are as fast as their explicitly typed counterparts. It is possible that type inference will enter the mainstream just like automatic memory management (with garbage collection) has become a standard feature of modern programming languages.