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

Chris Rebert cvrebert at gmail.com
Mon Aug 25 05:45:51 CEST 2008


On Sun, Aug 24, 2008 at 8:22 PM, Terry Reedy <tjreedy at udel.edu> wrote:
>
>
> Russ Paielli wrote:
> ...
>>
>> instance for which it is called. What I will say is that I think Python
>> syntax could be significantly simplified with the simple little convention
>> that I am proposing. All I ask is that you carefully read my proposal before
>> you reply. Thank you.
>
> I have.  It strikes me as an improvement over .attr and other ideas posted
> on c.l.p.
>
>    In Python, the class instance for which a method is called is
>    referred to within the method by the first formal argument.
>
> Somehow awkward.
>
>    By convention, that first argument is typically named "self".
>
> For public code among English speakers.  But how far this extends and for
> how long, given Unicode identifiers in 3.0, is a moot point for your
> proposal.
>
>    In Python, class instance methods are functions in which the first
>    formal argument refers to the instance for which the method was
>    called.
>
> In Python, class instance methods are functions accessed as an attribute of
> the class, in particular of the object passed as the first argument.  To me
> your discussion is weakened by the implication that Python has a method
> class separate from functions.  (Bound methods are specialized
> partial-function wrappers; functools.partial is the general version.) For
> instance
>
>    could even work for regular functions if the first argument is an
>    object with attributes and/or methods that can be accessed with
>    standard "dot" notation.
>
> Def statements produce functions.  Period.
>
>    This proposal takes no position of
>    whether the latter should be allowed or not.
>
> To repeat: former *is* latter with a particular access path.  So the
> question is not whether to 'allow' $ to work in functions; that *is* your
> proposal, whether you know it or not.  To do otherwise would require some
> other significant change to Python, one that would complicate it.
>
>     Four possible candidates for the choice of that symbol are "~",
>    "@", "^", and "$".
>
> You left out "?" (not too good ;-) and now, in 3.0, "`" (backtick, no longer
> an repr synonym).  The latter is lighter than "$" but perhaps more visible
> than ".", depending on the font.  Hmmm, a comparison:

Minor point, but the backtick is NOT up for grabs, at least as of a
discussion on this very list from last year.

Quoting a response from Guido:
"""
On 1/2/07, Chris Rebert <cvrebert at gmail.com> wrote:
> Thus, I propose one of the following as the new use for the backtick (`):

You're missing one of the main reasons for removing the backtick
syntax in the first place: the character itself causes trouble by
looking too much like a regular quote (depending on your font), is
routinely mangled by typesetting software (as every Python book author
can testify), and requires a four-finger chord on Swiss keyboards. No
new uses for it will be accepted in Python 3000 no matter how good the
idea.

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

Not that I understand the relevance of Swiss keyboards, but anyway,
there you have it.
Perhaps we need to alias __future__.backtick to __future__.braces so
people remember this ;)

- Chris
========
Follow the path of the Iguana...
Rebertia: http://rebertia.com
Blog: http://blog.rebertia.com

>
> self.d = sqrt(self.x*self.x + self.y*self.y)
>
> s.d = sqrt(s.x*s.x + s.x*s.x)
>
> .d = sqrt(.x*.x + .y*.y)
>
> $d = sqrt($x*$x + $y*$y)
>
> `d = sqrt(`s*`x + `y*`y)
>
> I think I like this last best.
>
> Terry Jan Reedy
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>



More information about the Python-ideas mailing list