There are a lot of questions on SO about static vs dynamic typing, but I haven't found a lot about a language having both. Let me explain.
It seems that dynamically typed languages have an edge when it comes to rapid prototyping, e.g. Python or Perl, while statically typed languages (like C++, OCaml) allow for more compile-time checks and optimizations. I'm wondering if there is a language that would allow both:
- first, rapidly prototype with dynamic typing, generic (i.e. accepting any type) print functions for easy debugging and REPL, and adaptation to changing design choices
- then, change a few things and compile the code into a library, with static typing for more safety tests and best performance. The things one changes to allow static typing could be for instance: declaring variables (but not annotating everything, thanks to type inference), adding a compiler switch, using specific functions instead of generic ones, etc.
In C# the default is static typing, but you can write:
dynamic fooVar = new FooClass();
in which case fooVar
is dynamically typed.
It seems that OCaml with http://www.lexifi.com/blog/runtime-types also offer something like this.
Please no subjective advice about which language is best, only objective features!