[Python-3000] iostack and Oh Oh

Phillip J. Eby pje at telecommunity.com
Fri Dec 1 21:55:15 CET 2006


At 11:52 AM 12/1/2006 -0800, Bill Janssen wrote:
>Paul Moore writes:
> > There is no expectation that all/most (or even
> > many!) libraries would be based on ABCs. Duck typing would remain the
> > norm. Although I'm not clear what the value of all this is, if the
> > resulting ABCs *don't* get used in real code.
>
>I'm not sure what it means to base a library on ABCs.  You base types
>on ABCs.
>
>But I'd hope that more library implementors would shift to documenting
>required interfaces for parameters where appropriate, rather than the
>current practice of either (1) not specifying anything, and forcing a
>caller to read the code, or (2) spotty and incomplete documentation of
>required methods, forcing smart callers to read the code.  And lots of
>library implementors don't know what methods are required if you need
>a value to support the "[k]" operation.  I would hope that eventually,
>for most widely used library packages, duck typing would *not* be the
>norm, because I think it's a source of both fragility and FUD in the
>Python world.

I would actually hope that library implementors would shift to using 
generic functions, since then they can just document what the function(s) 
are supposed to do, and people can just add methods to those functions for 
any object types they like, without needing to subclass anything, or have 
to deal with "interfaces" at all.

In other words, I just want to use my object with some operations that a 
library provides (or requires).  An "interface" is excise: something I have 
to mess with that doesn't directly relate to my goals for using the library.

Generic functions are type-safe duck typing because ducklib.quack(ob) 
doesn't rely on ob having a 'quack()' method that means what you think it 
means.  This solves the problem simply and directly, without introducing 
interfaces and ABCs and whatnot.  Either the operation is defined for the 
type or it isn't.

At most, an interface need only specify what operations must be defined for 
a type, in order to allow it to be used for a different operation.



More information about the Python-3000 mailing list