[Python-3000] Builtin iterator type

Jean-Paul Calderone exarkun at divmod.com
Tue Nov 21 18:22:31 CET 2006


On Tue, 21 Nov 2006 12:07:35 -0500, Jim Jewett <jimjjewett at gmail.com> wrote:
>On 11/21/06, Nick Coghlan <ncoghlan at gmail.com> wrote:
>> Aaron Bingham wrote:
>
>> > I agree.  In Java, interfaces are necessary because multiple inheritance
>> > is not supported.  I see no good reason to add an additional language
>> > mechanism for interfaces when multiple inheritance would do the job, AFAICT.
>
>> Just because multiple inheritance is *possible* in Python, don't make the
>> mistake of thinking that it is straight forward. Aside from mixin classes that
>> themselves inherit directly from object, multiple inheritance can get very
>> messy outside of tightly controlled type hierarchies
>
>Interfaces have almost exactly the same limits.

Having developed _extremely_ complex systems (often, the same system
repeatedly, sometimes using inheritance, sometimes using interface) with
each, I have to strongly disagree here.

>
>A mixin class is basically the equivalent of
>
>    (a)  A Java interface, plus
>    (b)  A matching default (possibly abstract) base class, plus
>    (c)  Automatic delegation (to the mixin), even for classes that
>need to inherit from something else.
>
>> (cooperative calls in particular can become a nightmare).
>
>If the method name is reused with different meanings, you have a
>nightmare no matter how you work it.

Not so.  Composition works much better than inheritance when this case
comes up, and composition and interfaces tend to go hand in hand.

>
>If the mixin knows that it is the the most base provider of a method,
>you have no problem.  Normally, this can be arranged by putting mixins
>at the end of the class statement.

It is often impossible to know this, except when every aspect of the
inheritance hierarchy is tightly controlled.  This is rarely, if ever,
the case for a class exposed by a library as part of its public API.

Jean-Paul


More information about the Python-3000 mailing list