[Python-Dev] OT: style convention: self vs. _ in new Norvig's book
Guido van Rossum
guido@python.org
Mon, 21 Jan 2002 14:02:49 -0500
> Wow; I didn't expect this to generate such a response. But I did post
> the code far before it was ready and put the "I could be talked out of
> it" there for a reason. So, thank you for your feedback! My reactions:
You're welcome. I'm always there to save a straying stranger. :-)
[snip]
> self: OK, I'll try it.
>
> My rationale was: I'm used to Java, where self is usually spelled '',
> and I figured '_' was the next best thing. I find it much nicer to read
> because 'self' is too intrusive; I want something that disappears.
I hear that in the Lisp world, when someone complains about the
parentheses, the standard response is "once you're used to it, the
parentheses disappear". So it is for Python's 'self'. :-)
> Compare:
>
> _.x, _.y, _.z = x, y, z
> self.x, self.y, self.z = x, y, z
>
> Besides saving 9 characters, I find that the first line I can read at a
> glance, ignoring the _, while the second I have to look at more
> carefully. I also like the symmetry of _._ in _._private_slot. However,
> I recognize I'm doing this as an outsider to the language without much
> experience reading/writing it. If it is really true that using '_' would
> be seen as a change to the language and not a personal quirk, then I
> agree that I shouldn't do it. The first hint I had of this was when I
> saw something on comp.lang.python (I forget the details) suggesting that
> an automated tool look for methods with first argument 'self'. So I'll
> try 'self' for a while, and hope I learn to like it (and learn to read
> the second sample line above in one glance). If I don't, I'll write
> here and give you all another chance to innundate me with reasons why I
> should.
Thanks!
> -Peter
>
> PS - Getting a personal request from Guido reminds me of the time I was
> at a conference and John McCarthy walked up to the booth of one of the
> Lisp vendors and said in his usual direct fashion "I hear you have a new
> version. You should send me one". The booth bimbo had no idea who
> McCarthy was and politely suggested he pay for a copy. Then someone in
> the booth with a little more experience came over and said "That's ok --
> it's his language, he can have whatever he wants."
What's a booth bimbo? :-)
--Guido van Rossum (home page: http://www.python.org/~guido/)