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:

    It is the will of God that we must have critics, and missionaries, and Congressmen, and humorists, and we must bear the burden. Meantime, I seem to have been drifting into criticism myself. But that is nothing. At the worst, criticism is nothing more than a crime, and I am not unused to that.
    Mark Twain [Samuel Langhorne Clemens] (1835–1910)

    The aim of all commentary on art now should be to make works of art—and, by analogy, our own experience—more, rather than less, real to us. The function of criticism should be to show how it is what it is, even that it is what it is, rather than to show what it means.
    Susan Sontag (b. 1933)

    Parents sometimes feel that if they don’t criticize their child, their child will never learn. Criticism doesn’t make people want to change; it makes them defensive.
    Laurence Steinberg (20th century)