

Why Dynamic Typing Is A Bad Idea - braindump03
https://stacktrace.so/2014/02/why-duck-typing-is-a-bad-idea/

======
lvh
This article doesn't really bring anything new to the table; it's yet another
rehash of "some errors can be caught at compile time and dynamically typed
languages do not do this so they are bad".

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.

~~~
masklinn
> unless you leave out testing, which can catch way more bugs, including ones
> that the compile-time type checker won't.

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.

------
jaimebuelta
Eh.... no

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...

------
nathell
Duck typing is not the same thing as dynamic typing. You can do the latter
without the former, and there are features akin to duck typing in some
languages normally thought of as statically typed (e.g., C++ templates).

------
mkesper
My favorite:

 _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._

[https://sqlite.org/testing.html](https://sqlite.org/testing.html)

~~~
tbirdz
But aren't compiler warnings also a form of static analysis?

------
spellboots
And this is precisely why there are no large, successful systems implemented
in dynamic languages, whereas all statically typed language projects have no
bugs whatsoever.

~~~
dkuntz2
Google was originally written in Python. The reason it was changed wasn't
directly due to Python being a dynamic language, but that the new programmer
was more familiar with C++ and that C++ would run faster.

~~~
mcphage
The person you were replying to was being sarcastic.

------
TelmoMenezes
The "hard to debug" claim is repeated ad nauseam, but never supported by real-
life examples. Typically it comes with some academic example that is not
actually hard to debug, plus some vague promise that in the "real world" nasty
stuff can happen. This article is not the exception.

------
LyndsySimon
Translation: When you name your method "output" and write no documentation,
you don't have a good idea of what's going to come out the other end.

------
MaybiusStrip
Shouldn't anybody browsing HN understand the difference between dynamic and
static typing? Who is even upvoting this?

~~~
thekaleb
Strong typing zealots?

------
artificialidiot
First, article confuses duck typing with dynamic typing. Second, it mentions
variable declaration semantics which has nothing to do with dynamic or duck
typing. Then promptly gives an example of operator overloading for an unnamed
language with unspecified semantics to prove his point. It doesn't say
anything about dynamic typing or why it is bad.

Keep up the good work, you'll be the next SV darling in no time.

------
almosnow
To the writer of this article: Just go find another career; plain and square,
you suck.

