Why the 'self' argument?

Harri Pesonen fuerte at sci.fi
Sat Sep 6 16:58:50 EDT 2003


Grant Edwards wrote:

> In article <Ucp6b.3992$ZB4.3874 at reader1.news.jippii.net>, Harri Pesonen wrote:
> 
>>I agree, it's not logical. I'm learning Python at the moment, and like 
>>it very much. This "self" thing seems to be the only odd feature,
> 
> It seemed quite natural to me, but perhaps that's because I'd
> used other languages that worked the same way.  Coming from
> Modula-3 and Smalltalk, the way classes worked in Python seemed
> quite intuitive.
> 
> OTOH, C++ seems like a real non-intuitive mess to me.
> 
>>it feels like the whole class feature was added later.
> 
> Why?

Because everything else in Python seems to be very compact, there are no 
variable type declarations, or variable declarations, or anything else 
unnecessary that can be omitted. I would like to have self omitted, it 
would make the class syntax more beautiful and compact. On the other 
hand, I would like to have real private methods.

Also I think that the class members should be explicitly declared. In 
general, it would be nice to have an option (like Option Explicit in 
Visual Basic) so that you can't assign to variables that have not been 
declared. It would probably make Python less error prone. Also if 
variable declarations could have the type, again some errors could be 
detected at compile time.

I have not written any real Python applications yet, so I'm not expert, 
these are just my thoughts at this point.

Harri





More information about the Python-list mailing list