Erreur de chargement de la page - Vimperator. Programming's Dirtiest Little Secret. This is another one I've wanted to write forever.
Twice a month, we revisit some of our readers’ favorite posts from throughout the history of Nettuts+.
Table of Contents. Duck typing. 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. In duck typing, a programmer is only concerned with ensuring that objects behave as demanded of them in a given context, rather than ensuring that they are of a specific type.
For example, in a non-duck-typed language, one would create a function that requires that the object passed into it be of type Duck, in order to ensure that that function can then use the object's walk and quack methods. In a duck-typed language, the function would take an object of any type and simply call its walk and quack methods, producing a run-time error if they are not defined. Instead of specifying types formally, duck typing practices rely on documentation, clear code, and testing to ensure correct use. Concept examples