Why self?

Delaney, Timothy tdelaney at avaya.com
Tue Jul 9 20:24:11 EDT 2002


> From: kosh at aesaeion.com [mailto:kosh at aesaeion.com]
> On Tue, 9 Jul 2002, Mark McEahern wrote:
> 
> > What you don't see, of course, is all the people who are 
> silent because
> > they're quite happy with self. prefixes and consider this a 
> pointless
> > discussion usually kept alive by people who refuse to learn 
> the idioms of
> > Python to their best advantage.
> >
> 
> I have to agree with you on this. I find self makes the code 
> very clear
> and much easier to maintain. Overall I am willing to use 

Very much so. I *always* use the this.variable form in Java to make it
explicit that I'm referring to an instance variable. Two reasons for this:

1. Even though we have a convention here of member variables being prefixed
with "m" (e.g. mVariable) I don't find this easy to see. An explicit
this.mVariable is much easier to see.

2. "this" is a Java keyword, and gets coloured in my editor. Thus I can
*very* easily pick out the member variables. Local variables are therefore
also easier to pick out, as they are not syntax coloured.

Exactly the same applies to Python, with the sole exception that self is
required, and so I don't have to put up with co-workers who don't like
putting self.name ...

Tim Delaney





More information about the Python-list mailing list