advice on programming style: is multiple inheritance bad?

Irmen de Jong irmen at -NOSPAM-REMOVETHIS-xs4all.nl
Sun Feb 1 14:37:03 EST 2004


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?


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++.

If you keep http://www.python.org/2.3/mro.html within
reach, I think you should be just fine using m.i. in Python.
I never had trouble with Python using m.i., but I tend to
avoid it and use it only where it really matters.

--Irmen de Jong



More information about the Python-list mailing list