Attack a sacred Python Cow

Terry Reedy tjreedy at udel.edu
Sat Jul 26 00:06:05 EDT 2008



Paul Boddie wrote:
> On 25 Jul, 22:37, Terry Reedy <tjre... at udel.edu> wrote:
>> Kay Schluehr wrote:
>>> This isn't the problem Jordan tries to address. It's really just about
>>> `self` in the argument signature of f, not about its omission in the
>>> body.
>> That is not at all how I read him, so I will let him respond if he
>> wishes.  The main problem moving a function from module scope to class
>> scope is prefixing the proper variables.  Adding a param name, whether
>> 'self', 's', 'this', or whatever, is trivial and hardly worth the ink.
> 
> He wrote the following of relevance:
> 
> "I added some classes to code that had previously just been functions,
> and you know what I did - or rather, forgot to do? Put in the 'self'.
> In front of some of the variable accesses, but more noticably, at the
> start of *every single method argument list.*"
> 
> And rounding off with this on the subject:
> 
> "The problem is that the explicit requirement to have self at the
> start
> of every method is something that should be shipped off to the
> implicit category."

There is no requirement to have 'self' in the parameter list.  It can be 
's', 'this', 'me', 'yo'(Spanish for I), or 'cls' (for class methods), or 
any other identifier in whatever language.
In 3.0, identifiers are not restricted to ascii but can be any unicode 
'word' as defined in the manual.

So the proposal would have to be that the compiler scan the function 
body and decide which dotted name prefix is the one to be implicitly 
added.  Have fun writing the discovery algorithm.  However, I think this 
is pretty silly.  Just write the name you want.

Or the proposal would have to be that 'self' is mandatory for all 
programmers in all languages.  I think *that* would be pernicious. 
People are now free to write the more compact 's.sum = s.a + s.b + s.c' 
if they want instead of the 'self' version.  And again, not everyone 
writes in English.

tjr




More information about the Python-list mailing list