What is "self"?
Rick Wotnaz
desparn at wtf.com
Fri Sep 23 08:11:14 EDT 2005
Roy Smith <roy at panix.com> wrote in
news:roy-DE5389.07461923092005 at reader1.panix.com:
> Ron Adam <rrr at ronadam.com> wrote:
>> You can actually call it anything you want but "self" is sort
>> of a tradition.
>
> That's true, but I think needs to be said a bit more
> emphatically. There's no reason to call it anything other than
> "self" and a newcomer to the language would be well advised to
> not try and be creative here. Using "self" is virtually
> universal, and calling it anything else will just lead to
> confusion by other people who have to read your code.
I've long thought that Guido missed an opportunity by not choosing
to use 'i' as the instance identifier, and making it a reserved
word. For one thing, it would resonate with the personal pronoun
'I', and so carry essentially the same meaning as 'self'. It could
also be understood as an initialism for 'instance'. And, because it
is shorter, the number of objections to its existence *might* have
been smaller than seems to be the case with 'self' as the
convention.
And as a side benefit, it would make it impossible to use as a loop
index a language feature that would be a huge selling point among a
lot of experienced programmers.
--
rzed
More information about the Python-list
mailing list