Arguments for static and dynamic types
Static type system advocates point out that without a type system, simple typing mistakes may result in failures in production. This is definitely true; anyone who has used a dynamic language has experienced it.
Dynamic language advocates point out that dynamic languages seem to be easier to program in.
This is definitely true for some kinds of code that we write occasionally, like code that uses eval
.
It's debatable for everyday code, and depends on the ill-defined term "easy".
Rich Hickey did a fantastic talk about the word "easy" and its relationship to the word "simple".
Watching that will show that it's not easy to use the word "easy" well.
Be wary of "easy".
The trade-offs between static and dynamic type systems are still poorly understood, but they definitely depend heavily on the language in question and the problem being solved.
JavaScript tries to continue executing even if that means doing data conversions that are nonsensical (like "a" + 1
returning "a1").
Python, on the other hand, tends to be conservative and throw errors often, as it will in the case of "a" + 1
.
Those are very different approaches with different levels of safety, but Python and JavaScript are both dynamically typed.
C will happily allow the programmer to read from arbitrary locations in memory, or to treat a value of one type as if it had another type, even if that makes no sense at all and leads to a crash. Haskell, on the other hand, won't even allow an integer and a float to be added together without an explicit conversion step added. C and Haskell are both statically typed, despite being wildly different.
There are wide variations within dynamic languages and within static languages. Any blanket statement of the form "static languages are better at x than dynamic languages" is almost certainly nonsense. It may be true of some particular languages, but in that case it's better to say "Haskell is better at x than Python".