indentation

Ionel Simionescu ionel at psy.uva.nl
Sat Dec 4 11:07:23 EST 1999


Gerrit Holl <gerrit.holl at pobox.com> wrote in message
news:19991203211232.A11045 at stopcontact.palga.uucp...
|
| no self... Why do I have to type it, if it's not possible to not type it?
|

When you do not type it,
the interpreter should figure out from the context of the call to which
object the method applies. In the most usual case [e.g. obj.method()],
finding out the object is a snap.
However, for complex class hierarchies, things get messy and there would be
a lot of work to get the answer. Moreover, making possible a positive answer
would impose heavily on the flexibility of the language.

However, it's not just about avoiding (un-necessary) complexity.
It also offers you more freedom. When object references are passed
explicitly,
it is easy to design classes whith methods that can be used
not just on the instances of the class but on other, unrelated objects as
well.

Conclusion: it's worth writing 'self', because it gives you more control.

ionel






More information about the Python-list mailing list