"Duck typing" etymology? [closed]
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this questionIs there a story behind the name ''duck typing'', I've heard ''if it looks like a duck, and sounds like a duck, let's call it a duck'' (or something like that), but why a duck? Why not ``if it looks like a _ and sounds like a _, let's call it a _''.
It sounds like a Flying Circus sketch, but I don't remember it. Is there a story behind the name?
Duck typing is a phrase borrowed from the much older "walk like a duck". The latter has been around far longer than the programming idea it describes. See answerbag.com
http://groups.google.com/group/comp.lang.python/msg/e230ca916be58835?hl=en&
Alex is involved... ;)
This is not really a programming question, but my guess: Ducks walk funny and they quack. This is amusing enough to turn it into a figure of speech. :-)
Quoting Wikipedia's article on Duck Typing:
The name of the concept refers to the duck test, attributed to James Whitcomb Riley, which may be phrased as follows: "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."
...and from the same page...
Alex Martelli made an early (2000) use of the term in a message to the comp.lang.python newsgroup. He also highlighted misunderstanding of the literal duck test, which may indicate that the term was already in use:
"In other words, don't check whether it IS-a duck: check whether it QUACKS-like-a duck, WALKS-like-a duck, etc, etc, depending on exactly what subset of duck-like behaviour you need to play your language-games with."
No, the analogy is that if a variable looks like an integer (for example), and acts as an integer, it must be an integer (type).
Duck typing means 'no explicit predeclaraction of type'.
精彩评论