The discussion over whether strong typing is better than weak typing
is settled [1], but not over whether static typing is better than dynamic
typing. Adherents of static typing thinks that the compiler should
check "correctness" by verifying type invariants, adherents of dynamic
typing think that is a waste of time.
I'm firmly in the latter camp. Because the compiler can't check
program correctness only type correctness. Type correctnes is
necessary for program correctness, but NOT sufficient. Static typing
adherents fail to recognize this, thus falsely believing that static
typing guarantees them more than what it actually does (blub).
Consider the article's birthdayGreeting example. Author is happy that
static typing catcges the birthdayGreeting("John", "20") bug because
"20" is not a number. But birthdayGreeting(" ", 123) is not
caught (" " is not a name) and neither is birthdayGreeting("Anna,"
-12335). birthdayGreeting("Anna" 4.5), though, is caught, which arguably
is wrong since 4.5 is an age.
This is actually very important since "type bugs" are trivially easy
to catch, while "semantic bugs" can stay undetected for years. An
account balance stored as a uint that overflows, a number that must be
prime at a certain program location, but isn't, a list that must not
be empty, etc. No, not even dependent types can guarantee these
invariants.
If you don't believe me, read up on some catastrophic bugs. Those that
have caused space ships to explode and cars to crash. To the best of
my knowledge, not a single one has been caused by bona fide type
errors. In the overwhelming majority of cases, the root cause has been
a semantic error.
[1] - Most people don't understand that typing is measured over at least
two axes, strong/weak and static/dynamic, and continue to conflate
weak typing with dynamic typing. C is statically typed and weakly
typed. Python is strongly typed and dynamically typed. Javascript is
weakly typed and dynamically typed.
I'm firmly in the latter camp. Because the compiler can't check program correctness only type correctness. Type correctnes is necessary for program correctness, but NOT sufficient. Static typing adherents fail to recognize this, thus falsely believing that static typing guarantees them more than what it actually does (blub).
Consider the article's birthdayGreeting example. Author is happy that static typing catcges the birthdayGreeting("John", "20") bug because "20" is not a number. But birthdayGreeting(" ", 123) is not caught (" " is not a name) and neither is birthdayGreeting("Anna," -12335). birthdayGreeting("Anna" 4.5), though, is caught, which arguably is wrong since 4.5 is an age.
This is actually very important since "type bugs" are trivially easy to catch, while "semantic bugs" can stay undetected for years. An account balance stored as a uint that overflows, a number that must be prime at a certain program location, but isn't, a list that must not be empty, etc. No, not even dependent types can guarantee these invariants.
If you don't believe me, read up on some catastrophic bugs. Those that have caused space ships to explode and cars to crash. To the best of my knowledge, not a single one has been caused by bona fide type errors. In the overwhelming majority of cases, the root cause has been a semantic error.
[1] - Most people don't understand that typing is measured over at least two axes, strong/weak and static/dynamic, and continue to conflate weak typing with dynamic typing. C is statically typed and weakly typed. Python is strongly typed and dynamically typed. Javascript is weakly typed and dynamically typed.