advice on programming style: is multiple inheritance bad?

John Roth newsgroups at jhrothjr.com
Sun Feb 1 21:22:23 EST 2004


"Joe Mason" <joe at notcharles.ca> wrote in message
news:slrnc1r2id.ea6.joe at gate.notcharles.ca...
> In article <401d5562$0$318$e4fe514c at news.xs4all.nl>, Irmen de Jong wrote:

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

Actually, it doesn't. For new style classes, Python
precomputes the method resolution order, so looking
up a method is simply flipping through a list of
dictionaries until it finds the right one. It's basically
O(n) in the number of classes in the hierarchy.

Given that you can add or remove attributes from
any class at any time, it's hard to see how it could
be any faster.

John Roth
>
>
> Joe





More information about the Python-list mailing list