

Death by Duck-Typing - abscondment
http://threebrothers.org/brendan/blog/death-by-duck-typing/

======
telemachos
I'm not sure I follow the argument (or agree with where the author places the
blame).

Notwithstanding Ruby's handling of type safety or its implementation of
arrays, isn't it my job (as the programmer) to know what kind of object I'm
getting from the helper library? That is, when I get 'h' (in his example), the
black box is how 'h' gets filled, not _what kind of collection object it is_.

Or am I confused?

~~~
tetha
This is entirely correct.

Duck typing basically assumes that the programmer knows what he is doing. Duck
typing especially assumes that the programmer does things more clever than a
static type system would be able to express right now. But that is fine. Since
this is duck typing, the programmer knows what he is doing by assumption.

Of course, however, this works in both directions. Duck typing puts a lot of
burden on the programmer. Yes, you don't have to annotate things with types,
but in fact, you have to worry MORE about types than using a statically typed
language. In a statically typed language with type annotations all over the
place, the compiler checks for simple and maybe even less simple errors. If
you have duck typing, the programmer needs to do this work, by defining clear
interfaces with clear documentations about the expected behavior of an object
passed in here or returned over there.

In my opinion, this is again an instance of more defensive or more aggressive
languages. Duck typing is more aggressive, as it requires more care of the
programmer but allows the programmer to do more things, while static typing
requires less care, but allows less things.

~~~
Paddy3118
To rip out a little of the reply by tetha above:

"If you have duck typing, the programmer needs to do this work, by defining
clear interfaces with clear documentations about the expected behavior of an
object passed in here or returned over there."

A compiler does not define clear interfaces with clear documentation for you.
If you are implying that to use duck typing, this is more likely to be done by
a programmer then this is a _good thing_ ; no matter what the typing.

In practice duck typing helps to get rid of needless duplication, and extended
class hierarchies in code, and proponents would state that less code is easier
to verify.

\- Paddy.

------
dangrossman
Be glad arrays in PHP are implemented internally as hash maps, so the average
inexperienced web developer doesn't run into issues like these.

