Multiple Inheritance [was Re: Accessing parent objects]

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun Mar 25 10:36:08 EDT 2018


On Sun, 25 Mar 2018 04:49:21 -0700, Rick Johnson wrote:

[...]
> Ruby is fundamentally _opposed_ to the idea of multiple inheritance  --
> as MI is rife with issues (technical, practical, and intuitive in
> nature) and thus, not a wise solution -- but you would have known that
> Steven

I know that many people consider multiple inheritance (MI) to be a bad 
idea. I would even agree with them that using MI is often over-kill, 
difficult to get right, and doesn't really scale well to large class 
hierarchies. (But then, what does?)

But sometimes MI is the easiest way to get the job done.

Michele Simionato has spent a *lot* of time writing about the limitations 
of MI, and alternatives such as mixins and traits. See his blog on 
Artima, a good place to start is here:

https://www.artima.com/weblogs/viewpost.jsp?thread=246488

In Ruby, mixins are a special kind of thing; in Python, mixins are merely 
implemented as ordinary classes, using multiple inheritance. There are 
pros and cons to each approach.

Actually, in Ruby, mixins are implemented using inheritance too, despite 
using distinct keywords.

https://andrewbrookins.com/technology/mixins-in-python-and-ruby-compared/



[...]
>> which is exactly when super() is most important.
> 
> Your assertion presupposes that MI is the only way to solve the problem
> that MI proposes to solve.

I don't understand your reasoning. All I'm saying is that if your langage 
doesn't support MI, then super doesn't gain you much except to save a few 
keystrokes.

Where super is really necessary is when your language supports MI, and 
specifically MI where the class hierarchy can form a diamond shape.


> And it is not only the Ruby folks who find MI
> to be woefully inadequate. The impracticality of MI has been the subject
> of much debate.

Indeed. And the correct word to use is *debate*.



-- 
Steve




More information about the Python-list mailing list