[Python-3000] PEP 3100 Comments

Michael Chermside mcherm at mcherm.com
Mon May 8 17:03:42 CEST 2006


Talin writes:
> Before we go to much further on this point, I want to get a sense of
> what exactly people are objecting to:

Good question. Answers below (speaking for myself only, of course!):

>     -- Are they saying that interface discovery is not important, or is
> bad style? (Its hard to do general transformations of objects from one
> form to another without it.)

No. Well, it's often bad style, but shouldn't be forbidden since it's
still sometimes useful.

>     -- Are they saying that the way isSequence and such implements
> interface discovery is wrong, and if it is, what's the alternative?

Yes it's "wrong" in that it's not 100% accurate. There IS no better
alternative.

>     -- Are they proposing some different model of interface discovery
> that they feel is better?

Not really. Interface discovery is HARD, and sometimes impossible.

>     -- Are they saying that duck types are wrong?

No, they're very useful!

>     -- Are they saying that interface discovery should be limited to
> formal types only, and not implicitly defined "duck types"?

YES!!

The whole idea behind duck typing is (1) the code being called doesn't
try to verify the type of the objects passed to it, it just uses
them; (2) the calling code choses to provide an object that implements
those methods that are needed, and not necessarily any others.

If the object passed doesn't behave as expected, then an error occurs
(usually an exception, sometimes erronious results). This is the
caller's fault, and the caller takes responsibility for it (consenting
adults here). A significant advantage of this approach is that the
object used might behave VERY differently than expected (eg: mock
objects for unit testing, or a proxy for some external object), and
that's OK.

If the called code attempts to verify the types that are passed to
it -- even via implicit discovery -- then it may not be possible to
use duck-typed arguments with that code. We call such code "duck-hunting
code" and generally tend to discourage it.

Well-we-don't-call-it-that-but-we-otta-lly yours,

Michael Chermside



More information about the Python-3000 mailing list