Why self?

holger krekel pyth at devel.trillke.net
Fri Jul 5 07:36:25 EDT 2002


Jesper Olsen wrote:
> Why is it necessary to use a "self" argument to class methods in python?
> 
> To me it seems a bit like doing object oriented programming in C...

There is some truth in this.  Python integrates well with C.  But of course,
the language wouldn't need to have you using 'self' to point to an object's
instance. 

> Why not make it implicit like "this" in C++?

Did you know that for larger projects people like to use "this->name" 
or prefix the member variables with 'm_' to introduce expliciteness
into c++?  
 
> I do not find it usefull that I can give it my own name.

which, in fact, hardly anybody ever does.  It's really all about
the credo "explicit is better than implicit".  To find out more
about python's design principles, have a look at

    http://www.python.org/dev/culture.html

cheers,

    holger





More information about the Python-list mailing list