[Python-ideas] PEP: Shorthand Symbol for "self"

Josiah Carlson josiah.carlson at gmail.com
Sat Aug 30 07:20:50 CEST 2008

On Tue, Aug 26, 2008 at 5:02 PM, 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 the
> 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" highlighted
> 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 each
> occurrence of "self" with "S". That was approximately 350 occurrences. I
> also replaced each occurrence of "cls" with "C", which was another 50 or so
> occurrences. The file size was reduced by 2.8%, many wrapped lines no longer
> 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, you
> 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 disadvantage
> I can think of is that searching on a single character can be problematic,
> 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 "C"
> as an accptable replacement for "cls". I hope that doesn't blow any fuses.

You can submit anything you want.  You know what Guido is going to say
with regards to self -> S and cls -> C as a proposed change to the PEP
8 style guide?  Something along the lines of "no".  He may even be
that polite.

What you do in your own code (that you write and maintain) is your own
business.  If S/C makes you happy: use it.  But don't be surprised
if/when someone starts working on that same code they start asking
(perfectly valid) questions about why you chose to go against the PEP
8 style guide.

 - Josiah

More information about the Python-ideas mailing list