Duck Typing - Criticism

Criticism

One issue with duck typing is that it forces the programmer to have a much wider understanding of the code he or she is working with at any given time. In a strongly and statically typed language that uses type hierarchies and parameter type checking, it's much harder to supply an unexpected object type to a class. For instance, in Python, you could easily create a class called Wine, which expects a class implementing the "press" attribute as an ingredient. However, a class called Trousers might also implement the press method. With Duck Typing, in order to prevent strange, hard-to-detect errors, the developer needs to be aware of each potential use of the method "press", even when it's conceptually unrelated to what he or she is working on.

In essence, the problem is that, "if it walks like a duck and quacks like a duck", it could be a dragon doing a duck impersonation. You may not always want to let dragons into a pond, even if they can impersonate a duck.

Proponents of duck typing, such as Guido van Rossum, argue that the issue is handled by testing, and the necessary knowledge of the codebase required to maintain it.

Criticisms around duck typing tend to be special cases of broader points of contention regarding dynamically typed versus statically typed programming language semantics.

Read more about this topic:  Duck Typing

Famous quotes containing the word criticism:

    When you overpay small people you frighten them. They know that their merits or activities entitle them to no such sums as they are receiving. As a result their boss soars out of economic into magic significance. He becomes a source of blessings rather than wages. Criticism is sacrilege, doubt is heresy.
    Ben Hecht (1893–1964)

    People try so hard to believe in leaders now, pitifully hard. But we no sooner get a popular reformer or politician or soldier or writer or philosopher—a Roosevelt, a Tolstoy, a Wood, a Shaw, a Nietzsche, than the cross-currents of criticism wash him away. My Lord, no man can stand prominence these days. It’s the surest path to obscurity. People get sick of hearing the same name over and over.
    F. Scott Fitzgerald (1896–1940)

    ... criticism ... makes very little dent upon me, unless I think there is some real justification and something should be done.
    Eleanor Roosevelt (1884–1962)