advice on programming style: is multiple inheritance bad?

Joe Mason joe at notcharles.ca
Sun Feb 1 18:51:11 EST 2004


In article <401d5562$0$318$e4fe514c at news.xs4all.nl>, Irmen de Jong wrote:
> Uwe Mayer wrote:
> 
>> However, this would cause A2 to have two super classes A1 and SuperA - which
>> is possible of course in Python.
>> 
>> My question is: is that bad programming style?
>> From C++ and Java we "learn" that you shouldn't do that.
> 
>  From C++? Didn't think so... C++ is perfectly capable of
> multiple inheritance. Or do you mean that you can get into
> trouble quickly because of the various access levels,
> virtual base classes etc?

When profiling a large app at work, we discovered that in C++ accessing
every parent class after the first is quite slow.  We were able to just
flip the order of inheritance for some classes, but if you're planning a
complex use of multiple inheritance you should keep that in mind.  (I'm
just assuming it has the same effect in Python.)

> Anyway my feelings about this subject:
> I'm not stronly in favor of multiple inheritance
> but I'm also not strongly against it.
> In my experience there are times that I find m.i.
> sorely lacking in Java because I want to do things
> like mix-in classes. At other times I got myself into
> trouble with a complex m.i. class tree in C++.

Yep, I agree with this.  A mix-in sounds like what the OP was talking
about, so that should be fine, but if it starts to get tangled, stop and
think about using a delegate or something instead.

Joe



More information about the Python-list mailing list