There are many questions about SO about static and dynamic typing, but I have not found much about a language that has both. Let me explain.
Dynamically typed languages seem to have an advantage when it comes to rapid prototyping, for example. Python or Perl, while statically typed languages (for example, C ++, OCaml) allow for additional checks and optimization of compilation time. I am wondering if there is a language that would allow:
- first a quick prototype with dynamic typing, a common (i.e., any type of reception) print function for easy debugging and REPL, as well as adaptation to changing design options
- then change a few things and compile the code into a library, with static typing for safer tests and better performance. Things that can be changed so that static typing can be, for example: declaring variables (but not annotating everything thanks to type inference), adding a compiler, using certain functions instead of general ones, etc.
C # uses static printing by default, but you can write:
dynamic fooVar = new FooClass();
in this case fooVar dynamically typed.
It seems that OCaml from http://www.lexifi.com/blog/runtime-types also offers something like this.
Please, not subjective advice, which language is best, only objective functions!
source share