[Python-Dev] OT: style convention: self vs. _ in new Norvig's book

Guido van Rossum guido@python.org
Mon, 21 Jan 2002 11:07:59 -0500


> http://norvig.com/python/python.html
> 
> Peter Norvig is about to supply
> Python versions of the algorithms with
> the 2nd edition of his AI: A Modern Approach.
> 
> So far, so good. In the section about
> coding convetions he says:
> 
> ¦In general, follow Guido's style conventions,
> ¦but I have some quirks that I prefer (although I could be talked out of them):
> ...
> ¦* _ instead of self as first argument to methods: def f(_, x):
> ...
> 
> I'm perfectly aware that the 'self' thing it is just a convetion,
> OTOH much of the cross-programmer readability
> of code relies on such convention.
> 
> It is good, bad or irrelevant to have such
> an authoritative book (although about AI not
> Python directly) adopting such a line-noisy
> convention?
> 
> Maybe nobody cares, but I preferred not to
> let this go unnoticed. Someone who cares
> could try to discuss the issue or make it
> apparent to Mr. Norvig.
> 
> Opinions?
> 
> regards, Samuele Pedroni.

Peter:

My apologies for butting in here without doing full research.  I don't
know how you reached this set of conventions, so maybe you've got a
very good reason; but I don't see it on your webpage.

Two of those coding conventions look really ugly to me: 2-space
indents and _ for self.  I think the code will look horrible!

I think everyone should be able to make their own style choices, but I
ask you to reconsider.  If you have to reconsider one, I would beg you
to use 'self' like everybody else.  The _ name is already overloaded
with multiple meanings in the Python community: it's a shorthand for
the last evaluated expression in interactive mode, and some people use
it as a dummy variable to assign uninteresting results to.

Almost the entire Python community is happy with 4-space indents; if
you're worried about your lines getting too long, that's usually a
hint that your code can be restructured in a way that's easier on the
reader's eye/mind anyway.

--Guido van Rossum (home page: http://www.python.org/~guido/)