开发者

The complexity of member looking up: Python Vs. Javascript

I am curious about the complexity of Python and JS 's looking up:

Python supports multi-inheritance, which affects the member lookup. Specifically, when referencing a member from an instance of a class, the process will start from the instance's dict, then to the class of the instance, then up to the super classes of the class of the instance, which for each super class, it has its own super class list..... which seems to end up开发者_开发知识库 with the complexity to be exponential (theoretically).

While it seems that the JS's member lookup time is linear -- which just has to trace back to the prototype chain.

Am I reasoning the right way? or I am missing something?


You're missing the fact that MI is very, very rarely used in Python, usually only for mixins where the inheritance chain tends to be very short anyways.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜