is Python fully object oriented ?

Martijn Faassen m.faassen at vet.uu.nl
Sat Jan 13 08:27:24 EST 2001


Max Møller Rasmussen <maxm at normik.dk> wrote:
> It's the only thing about Python that bothers me endlessly, having to
> explicitly pass "self".

Note that in the case of attributes that are mutable, you can use
local variables if you like:

def method(self):
    foo = self.foo
    foo.do_this()
    foo.do_that()
    return foo.get_bar() + foo.get_baz()

and since you prevent extra lookups, may in some cases even speed up 
your code.

In the case your attributes are immutable objects, you need to make sure
they're changed in the end if you use this technique:

def method(self):
    foo = self.foo
    foo = foo + 12
    ... lots more ..
    self.foo = foo

If you program your objects to be persistent in the Zope Object Database,
you have to treat all atttributes as immutable like this.

[snip]
> Is there a REALLY good reason that it has to be explicitly declared ?

Yes, readability and maintainability.

Or are you only complaining about having it explicitly in your argument
list, and you'd like it to be there implicitly, but that you still
have to use it explicitly? I'd say that'd be a bit inconsistent.

Regards,

Martijn
-- 
History of the 20th Century: WW1, WW2, WW3?
No, WWW -- Could we be going in the right direction?



More information about the Python-list mailing list