Is it advisable to replace 'self' with '_' or 'I' or something shorter?

Carl Banks imbosol at vt.edu
Tue Jan 21 17:53:47 EST 2003


oofoe wrote:
> Hi!
> 
> jbperez808 at yahoo.com (Jonathan P.) wrote in message news:<f57664b9.0301110959.5b1439da at posting.google.com>...
>> I agree with the fact that explicit use of self is good
>> for code readability, however it tends to make code lines
>> too long.  Since 'self' is just a convention, I wonder if
>> people out there have tried replacing it with a one-character
>> equivalent without encountering any problems.
> 
> I dislike the word 'self' for the method's object argument. It's
> clumsy to say and lends an unwarranted arrogance and formality
> to the method call. I prefer the much more friendly name 'my'.
> It's one letter longer than your preferred length, but it's
> very natural. To paraphrase Mark Twain, it's a name that's willing
> to roll up its sleeves, spit on its hands and get right to work,
> instead of setting out for a scenic sail across a vast ocean of
> verbose bureaucratese. See for yourself:
>
[snip]
> 
> I'm only half joking.


If I were starting a new language from scratch, I might actually go
for this convention.  Although the rule of thumb is that variable
names should be nouns, having the dispatching object be an adjective
is a nice way to set it apart.  It's also short.

(Actually, if I were starting a new language it would use
multimethods, but that's another story.)

But I always thought "self" was one of those conventions it's best not
to stray from.


-- 
CARL BANKS




More information about the Python-list mailing list