Duck Typing

dead-metaphor Folk TaxonomySoftware Programs

Categories: software-engineeringphilosophy

What It Brings

“If it walks like a duck and quacks like a duck, then it is a duck.” The duck test is an old piece of abductive reasoning — identify a thing by its behavior, not its pedigree. In programming, duck typing means that an object’s suitability is determined by the presence of certain methods and properties rather than by its declared type or class hierarchy. The duck is doing serious epistemological work: it encodes a pragmatist theory of identity where what you do matters more than what you are.

Key structural parallels:

Where It Breaks

Expressions

Origin Story

The “duck test” predates computing by over a century. It is commonly attributed to the poet James Whitcomb Riley (circa 1849): “When I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck.” The phrase was later used in Cold War-era American political rhetoric to identify communist sympathizers: if someone acts like a communist, they are a communist.

In programming, Alex Martelli coined the term “duck typing” in a 2000 post to the comp.lang.python newsgroup, applying the duck test to Python’s approach to type checking. The term quickly spread through the Python community and then to Ruby, JavaScript, and other dynamically typed language communities. It gave a memorable name to a practice that these languages had always used but had never branded so effectively.

The metaphor’s success lies in its compression: a complex philosophical position about the nature of identity (pragmatism, behaviorism, the primacy of function over form) is packed into a single farmyard image that any programmer can remember and invoke.

References

Related Mappings