[Python-ideas] PEP: Shorthand Symbol for "self"
russ.paielli at gmail.com
Wed Aug 27 19:21:54 CEST 2008
Normally I agree with you on the single-character identifiers, but I
consider this case an exception. Lets not forget that C++ and Java use
zero-character identifiers for "self", and I don't hear a din of complaints
that it harms readability.
My code does not appear to me to be any less readable to me when I
substitute "S" for "self". The fact that it is a capital letter helps a bit
here, I think. The fact that it usually appears as "S.attr" rather than just
"S" also makes it stand out clearly.
I just don't see the problem with having an "approved" shorthand form for
self when it does not require any changes in the language itself.
On Wed, Aug 27, 2008 at 12:11 AM, Cesare Di Mauro <cesare.dimauro at a-tono.com
> On 27 aug 2008 at 02:02:39, Russ Paielli <russ.paielli at gmail.com> wrote:
> > My editor, Xemacs, also highlights the word "self." I personally find
> that a
> > bit annoying, and perhaps that is part of the reason I don't appreciate
> > word. When I write an algorithm, I don't want to see some artifact
> > highlighted, as if it is somehow the most important part of the
> algorithm. I
> > like seeing keywords highlighted, but I don't want to see "self"
> > because it is only a convention. Maybe I'm alone on that.
> > As I wrote earlier, I copied one of my larger Python files and replaced
> > occurrence of "self" with "S". That was approximately 350 occurrences. I
> > also replaced each occurrence of "cls" with "C", which was another 50 or
> > occurrences. The file size was reduced by 2.8%, many wrapped lines no
> > need to wrap, and I like the way it looks.
> > I understand that people like to have "one true way," but I think Python
> > programmers are adaptable enough to handle this one. When you read code,
> > certainly need to read the argument names anyway, so the fact that "S" is
> > being used instead of "self" should be obvious. The only minor
> > I can think of is that searching on a single character can be
> > but if you are using an IDE, that should not be an issue (and I can't
> > remember ever searching on "self" anyway).
> > One of these days, when I get a chance, I may write an informational PEP
> > recommending the use of "S" as an acceptable replacement for "self", and
> > as an accptable replacement for "cls". I hope that doesn't blow any
> > Have a nice day.
> > --Russ
> I absolutely disagree. It's the same thing that happens when we use one
> character identifiers: the code becomes less readable.
> Identifiers must be self-explicative.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas