use of "self", was "No Do while/repeat until looping construct in python?"

Chermside, Michael mchermside at
Mon Mar 17 18:03:56 CET 2003

William Sonna writes:
> Yes, the constuctor is clear as can be.  The rules in Java are also clear
> as can be, and evey bit as clear as the self in Python - local variables
> or function parameters overshadow instance variables of the same name. But
> I am not troubled at all by the enhanced clarity that self provides.
> What I am sick of is getting nailed by the interpreter for forgetting to
> add "self" to every lousy instance variable name - or even worse - having
> it treat my omission as a local variable.  The mandatory self is itself a
> source of errors, and I believe based on my own experience that it creates
> more errors than it prevents.

Aahh... I think I now understand why it is that you and Guido diverged on
this one. You say that you "are not troubled at all by the enhanced clarity"
of explicitly using "self". Your problem with it is that when you WRITE the
code you often forget it, thus leading to lots of errors (when your variable
is presumed to be local).

Now, I could try telling you that as you use Python more, you'll start
getting used to it and will forget the "self" less often. But saying that
doesn't address your (very real) problem... you (and others, particularly
those coming from common languages like C and Java) make more mistakes when
writing code. The language design has traded some pain at time of WRITING
code for (as you put it) "enhanced clarity" in READING the code.

Well... that's a language design decision, and it's the kind of thing that
goes to the core of a language. Python was (IMHO) designed largely to be
easy to READ. In many little ways it is more verbose than similar languages
(which is more of a pain to type). And it requires you to state lots of
things explicitly instead of guessing what you intended. But the REASON for
these decisions was in order to emphasize the READABILITY.

There are lots of arguments for this (code gets read 10 times as often as
it gets written, yada yada yada...), but you don't have to agree. You 
should, however, realize that Python is designed this way on purpose...
valuing readability much higher than "writability".


-- Michael Chermside

More information about the Python-list mailing list