This question appears to be fairly well tread, for example:
- Do dynamic typed languages deserve all the criticism?
- What is the supposed productivity gain of dynamic typing?
- etc.
However, most questions and answers seem to compare statically typed languages like Java and C++ with dynamically typed languages like Python and JavaScript. This seems to be a different comparison - Java and C++ are verbose, non-interactive, and generally difficult to work with for reasons outside of their type systems.
I'm more interested in using static languages like Swift or Haskell as the basis of the comparison.
- These languages have REPLs, interactive coding, or equivalents
- These languages have type inference (as does C++)
- These languages have easy-to-use "generics"
- These languages have ADTs, which solves problems like JSON parsing
We can imagine a variant of Swift with a form of Structural Typing, where:
func foo(bar) { return bar.baz() }
Is valid syntax for any call in which an object with a baz()
member is passed, and the return type is that of the object's baz()
- effectively creating an anonymous protocol Foo<T>
with member func baz() -> T
.
This can be translated to JavaScript by s/func/function/g
, but all of the type safety would be lost.
What's the advantage of dynamic typing, compared a static typed language with a good type system?