[Python-3000] Discussions with no PEPs

Phillip J. Eby pje at telecommunity.com
Tue Mar 13 19:33:20 CET 2007


At 01:29 PM 3/13/2007 -0400, Barry Warsaw wrote:
>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>On Mar 13, 2007, at 12:05 PM, Phillip J. Eby wrote:
>
> > However, more people are under the impression that interface
> > testing is
> > safe and pure and smell-free, so there's more of a barrier to
> > overcome for
> > them to learn why it's wrong, without them first getting bitten --
> > either
> > by their own code or somebody else's.
>
>Phillip, could you sum the argument up as this:

Only if I were willing to making it sound like an argument over style 
instead of one of substance.  :)


>being against
>interface testing as just a fancy isinstance() test, but that
>adaptation and/or generics is a better way to go because the former
>is a LBYL pattern while the latter is a Just Do It pattern.

It's *similar* to this, certainly.  However, that's like saying that murder 
is bad because it's an instance of the Sin pattern.  If the Sin pattern 
also includes things like overindulgence in chocolate, then it seriously 
understates the part where somebody dies!

In other words, there are plenty of instances where LBYL might be "sinful", 
but it doesn't do any harm besides making your code "fat".

Whereas, type and interface testing of the variety practiced by pydoc and 
older Zopes, well, that *hurts other people too*.

So I want to keep it the hell away from the stdlib, because we don't need 
more pydoc-style hassles.

Sure, the parts of pydoc that work, work very nicely -- for built-in 
types.  But it's a terrible headache for people who want to use it on 
anything *else* -- which is precisely the thing that interfaces are 
theoretically *supposed* to avoid -- but don't in practice.

Superficially, pydoc is clean code because it uses "interfaces" (the 
inspect module's various isfoo() functions), but in reality it's just a 
perfect example of how that approach goes horribly wrong.  (It shouldn't be 
necessary for me to make all my callable objects have 'func_code' 
attributes in order to make pydoc present their signatures, for example!)

So, if I wanted to try to sum up my argument as briefly as possible, I 
would say:

Using interfaces for type testing provides a false sense of confidence that 
one's code is "clean", extensible, and reusable, while in fact creating 
endless headaches for anyone who actually tries to reuse it.

In contrast, using isinstance() may sometimes be a necessary evil, but few 
people are under the false impression that the resulting code is actually 
clean or reusable.  So it does comparatively little harm, because people 
usually practice it in moderation.

Had pydoc only had isinstance() to play with, it might have been less 
tempting to spread isfoo() junk throughout its entire code base.  And if it 
had generic functions to play with (or adaptation to an IDocumentable 
interface), it would've been able to avoid the whole issue in the first place.



More information about the Python-3000 mailing list