On 11/15/06, Greg Ewing <[EMAIL PROTECTED]> wrote: > George Sakkis wrote: > > > class Container(object): > > > > class Sequence(Container): > > > class Mapping(Container): > > > > Note that this does _not_ disallow duck typing; anyone is perfectly > > free to define a method len() in a class that does not extend any of > > the above so that a client can call x.len() successfully. > > What's the point, then? What benefit do I get from > extending Sequence if I can achieve the same thing > without bothering?
For one thing, the implementations you get for free for the methods that can be implemented without needing to know the specifics of the concrete class (think DictMixin, ListMixin and friends; all these would move there). So yes, for the nitpickers out there, these are not interfaces in the Java sense (or pure virtual classes in C++) but abstract classes. And for two, not everyone feels comfortable with duck typing. People who consider (for better or for worse) isinstance() safer than hasattr()/getattr() would be accomodated too. Why do we have to alienate those folks telling them they are wrong when both approaches can coexist, as it happens for LBYL vs EAFP error strategies, procedural vs OO vs functional paradigms, and other dichotomies and n-otomies that Python has successfully brought together ? George _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com