replacing instance __setattr__

Jonathan Hogg jonathan at onegoodidea.com
Tue Jul 9 05:36:17 EDT 2002


On 9/7/2002 5:23, in article
mailman.1026188712.26963.python-list at python.org, "Tim Peters"
<tim.one at comcast.net> wrote:

> BTW, bound method objects aren't methods because they're bound
> <wink>:  the OO part of "a method" is the part that figures out where to
> dispatch to, and in a bound method object that part has already been
> computed and frozen (cached in the BMO).  At the point it's just a flavor of
> ordinary function.

Hmmm. That's arguably incorrect. The OO part of method dispatch is that the
function called is looked up per-object. This is clearly done if the pointer
to the function is kept in the object's dictionary.

Keeping the method table in the class instead of the object is, and always
has been, purely a memory optimisation. In traditional OO languages, the
methods cannot vary between different objects of the same class and
therefore keeping the table in the object is unnecessary when it can be kept
in the class and pointed to from the object.

The difference between a bound method and a(n unbound) method is that the
'self' object has been associated. When the method table is kept in the
class this has to be done at dispatch time, when the method is already
associated with the object it need only be done once.

All methods are a flavour of ordinary function. In other OO languages this
may be made less clear, but in Python, with it's explicit 'self' reference,
this is made obvious.

-classless-prototype-languages-are-still-object-oriented-ly y'rs,

Jonathan




More information about the Python-list mailing list