Why Dynamic Typing Is A Bad Idea
stacktrace.so
stacktrace.so
The article claims that dynamic typing can lead to hard-to-track bugs. That is certainly true, but only paints half a picture: for example, in dynamically & strongly typed languages such as Python, Clojure or Erlang, you'd get errors instead of the wonky type-changing behavior of a weakly typed cousin such as Javascript. Secondly, just because dynamically typed languages do not catch certain classes of bugs at compile time doesn't really say much unless you leave out testing, which can catch way more bugs, including ones that the compile-time type checker won't.
The final paragraph says a lot:
Duck typing is nice for rapid prototyping but you
may not want to use it in any production code. It’s
terrible to debug, hard to test and sometimes leads
to bugs occurring extremely rare.
The article does not make the testing argument and only makes the sometimes-hard-to-debug argument.Dynamically typed languages can be used to produce reliable systems just fine; consider Erlang.
1. which sadly tends to be the usual state of the industry, as distasteful as it is. Static typing bringing some sort of "mandatory testing" is thus something of an argument.
2. good static type systems also make testing easier, see e.g. specification testing (quickcheck) in Haskell versus Erlang. I think Haskell's is much more enjoyable.
3. Dependent typing.
> The article does not make the testing argument and only makes the sometimes-hard-to-debug argument.
Which is not really correct anyway, most people who've had to debug C++ templates soup don't argue that it's easier to debug than Python code.
While the kind of bugs that are stated on the post are possible, in practice they are not seen (or at least, not commonly) and not that difficult to catch and correct. On the other hand, they remove the need for constant checking that a variable is of the correct type (which is handy, for example for refactoring code)
I know that dynamic languages are a little scary at the beginning (because that was what happened to me when I was learning Python, coming from a C/C++ background), but the truth is that kind of "protection" is not that necessary
Also, there are LOTS of production systems using dynamic languages that are working just fine...
Static analysis has not proven to be especially helpful in finding bugs in SQLite. Static analysis has found a few bugs in SQLite, but those are the exceptions. More bugs have been introduced into SQLite while trying to get it to compile without warnings than have been found by static analysis.
Keep up the good work, you'll be the next SV darling in no time.