[Python-3000] duck typing

Michael Chermside mcherm at mcherm.com
Mon May 8 15:18:47 CEST 2006


Bill Janssen writes:
> I don't want to ever again use a library that claims to export a
> "dict" object, only to find (later) that the implementor hasn't
> implemented some of the methods of the real "dict" type because he
> thought they wouldn't be called.

And there is the crux of the matter. I *want* to use a language
where the implementor of a "dict-like-class" need not implement
those methods of dict that she knows won't be used in this
quick-and-dirty dict-like-class.

> Or because he was too lazy to
> document the interface he'd actually implemented.  "Duck typing"
> encourages this kind of ramshackle development.

"Ramshackle" development is appropriate for many kinds of tasks.
For LIBRARY code, there is no excuse for failing to document the
interface, and while there are excuses for implementing less than
the full dict interface, they need to be justified. (Eg: it's
perfectly reasonable to create a dict-like class that prohibits
deleting entries.) But duck typing DOES have its uses.

-- Michael Chermside



More information about the Python-3000 mailing list