[Python-ideas] PEP: Shorthand Symbol for "self"
Andrew Akira Toulouse
andrew at atoulou.se
Mon Aug 25 08:10:21 CEST 2008
I agree with Brett.
While it's true that $ is four character shorter than 'self.', it also loses
expressiveness by doing so. The point here seems to be that it distinguishes
local variables with instance variables. Whereas 'self.' conveys the idea
that this is an instance variable clearly, a symbol such as '$' or '@' does
not.
It's also true that using 'self' is a convention -- you can easily use 's'.
So if you're enough of a nutcase to REALLY want to save those precious four
extra characters, well, you can save three. Meanwhile, adding @ or $ to
syntax would confuse a well-established, well-understood, and
newbie-friendly practice and complicate the language's grammar. Not to
mention, prefixing a variable with $ might be distracting to programmers who
do PHP for a living. Yet another mental load to bear.
It is not a blind spot. I have said before, if not on this list, then to
fellow programmers, that I like Python because 'self.' is not implicit or
substituted with a symbol that I don't automatically grok. This is, in my
opinion, what Brett meant by self-documenting, and I'm inclined to agree. I
don't like programming in languages that don't make as clear a distinction
between local variables and instance variables. And it's not because I'm
used to programming in Python, either, as I am a student have seen more Java
code than Python, and took up Python as a hobby. Perhaps it is you who,
having (possibly) seen implicit or abbreviated instance variables day in and
day out, have burnt them into *your* brain. I certainly haven't.
--Andy
On Sun, Aug 24, 2008 at 10:04 PM, Russ Paielli <russ.paielli at gmail.com>wrote:
> On Sun, Aug 24, 2008 at 9:39 PM, Brett Cannon <brett at python.org> wrote:
>
>> On Sun, Aug 24, 2008 at 7:25 PM, Russ Paielli <russ.paielli at gmail.com>
>> wrote:
>>
>> > Think about this way: it's 80% less clutter. I am a compulsive
>> minimalist,
>> > and one of the reasons I like Python is because it minimizes clutter. I
>> > probably let clutter bother me more than I should. I really appreciate
>> the
>> > lack of semicolons all over the place. Some would call that trivial, but
>> I
>> > call it significant.
>>
>> You call it clutter, I call it information. We have kept 'self'
>> explicit for a reason; it's self-documenting.
>>
>
> First, "self." conveys no more "information" than the "$" I am proposing,
> but it requires five times as many characters. If that's not clutter, I
> don't know what is.
>
> Second, "self." actually conveys *less* information than "$", because it's
> meaning depends on whether or not the first formal argument was actually
> "self".
>
> For the record, I gladly concede that I probably don't know as much about
> Python as most of the other people on this mailing list (as I wrote earlier,
> I am an aerospace engineer). But I also sense that many Python experts have
> a blind spot on this matter for some reason. I guess these folks are just so
> used to seeing "self." everywhere that it has burned itself into their brain
> to the point that they don't see it as the clutter that it is.
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20080824/60fb249f/attachment.html>
More information about the Python-ideas
mailing list