[Python-3000] Builtin iterator type

Jim Jewett jimjjewett at gmail.com
Tue Nov 21 18:07:35 CET 2006


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.

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.

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.

If you have multiple mixins each of which may or may not implement
methods with the same name (such as "save") *and* that name won't be
found on object ... then it gets a bit ugly.  IMHO, it still isn't any
uglier than the Java equivalent of sequentially calling the method for
each interface separately.

-jJ


More information about the Python-3000 mailing list