Real Problems with Python

Justus Pendleton justus at my-deja.com
Mon Feb 14 20:37:27 CET 2000


In article <slrn8aec0e.lqg.neelk at brick.cswv.com>,
  neelk at alum.mit.edu wrote:
> > > 3. Multiple inheritance is unsound
> > >
> > >    By 'unsound' I mean that a method call to a method inherited by
a
> > >    subclass of two other classes can fail, even if that method
call
> > >    would work on an instance of the base class.
> Here's some code:
>
> class Foo:
>    x = 99
>    def frob(self):
>        print "%d bottles of beer" % self.x
>
> class Bar:
>    x = "bar"
>    def wibble(self):
>        print "Belly up to the " + self.x
>
> Note that all the operations on Foo and Bar work safely for direct
> instances of Foo and Bar.  But if you define a subclass like so:
>
> class Baz(Bar, Foo):
>    pass

In an earlier post you mentioned that Dylan gets this "right" but as I
understand it, in Dylan two classes with the same getter generic
function ("x" in this case) are "disjoint - they can never have a common
subclass and no object can be an instance of both classes" (from the
Dylan Reference Manual section on Slot Inheritance).  It seems like
Dylan resolves this by simply saying you can't write code like that, not
by making Multiple Inheritance safer.  Or am I missing something?


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list