Prevent common typing bugs
A type system would have caught most of those problems at “compile” (or linting) time and helped you shipped less buggy software to your clients. Of course there are many other types of bugs that static typing won’t catch but it will reduce your bugs significantly4.
A statically typed language can help a compiler generate better code because it have more information about the code. Type hinting in dynamic languages like PHP won’t make the code faster because the only way to validate the types is at runtime which will actually make it slower.
Enable better tooling
Just like the compiler itself, the language tools like it’s completion library or jump to declaration tool can use the added information of the types in the code to know better what to do. For example if you will add type hinting in Python for the class you expect to get in the argument you will have all it’s method in the auto completion pop-up and you will be will be able to jump to the implementation of a function you called because the IDE/editor will know what class you called.
I think this is one of the most important points in favor of static typing that is often overlooked and when you realise that you need it, it will probably be too late.
Document your code
Another small but nice improvement of statically typed code is that the code really document itself. Of course static typing won’t replace all your comments but in dynamic typing you often see something like JSDoc or docstring that litter your code with with verbose comments about the function arguments and return type. All of that can fit in a single line of the function declaration like with TypeScript and Python 3 type hinting.
In conclusion I personally think that static typing is the right way to go. Dynamic typing with optional type hinting like TypeScript and Python 3 are a nice middle ground if you feel that statically typed language are too restrictive.
- It was recently announced that Ruby 3 will have static typing. [return]
- Python 3.4 have introduced type hinting to the language but without built in type checking. [return]