There are a lot of programmers who wax poetic about the benefits of static typing. Make no mistake there are some benefits, but at the same time programmers talk about them, they are downplaying the cons and the benefits of the other side of the coin, dynamic typing.
- Dynamic typing lets you get values into and out of your program a lot easier. You don’t have to write a new type for every little interaction with the outside world. You can just receive the values as they are and bind them to concrete types when you need them and deal with any errors on your time, not the compiler's.
- In dynamically typed languages like clojure there are a few generic data types and every function you ever write can operate on every one of them instead of having some functions operate on some types and not on others.
- Dynamic typing makes writing tests and running them easier. I don’t usually hear this argument but with dynamic typing you can save a file and you don’t have to compile it before you test, so tests can run automatically on save without the usually long interruption of the compiler. There are exceptions here like Go, where the compile time is very fast.
- Dynamic typing usually brings a REPL. The REPL is the best way to run code as you write it. I know statically typed languages like Haskell have one too but in my experience nothing beats a dynamically typed REPL, especially something like Clojure’s REPL.
- Less ceremony. There are static languages that infer types so you may never wind up manually typing a type, but that’s not the case in widely used languages like c# or java. The oftentimes clumsy syntax and cognitive load of trying to coerce types back and forth at the edges of your app, network or database boundaries stifles productivity.
There are downsides too which are widely reported in many places, probably too widely reported…
- Static analysis is harder than with statically typed languages. A lot harder. A static analyzer can catch a lot of bugs that might bite you in a dynamic language.
- Less “built in” documentation. Types can usually tell you what to expect when you pass data between functions. Dynamic languages rely on things like docs in comments, but in the clojure world at least there are some solutions.