What is "self"?
desparn at wtf.com
Fri Sep 23 17:41:44 CEST 2005
Terry Hancock <hancock at anansispaceworks.com> wrote in
news:mailman.851.1127486762.509.python-list at python.org:
> On Friday 23 September 2005 07:11 am, Rick Wotnaz wrote:
>> 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.
> How exactly is that? Anybody who uses "i" as a variable name
> for anything other than an innermost loop index is a sick and
> twisted code sadist.
> You'd prefer what? "count" or "kount" or
> "i_am_an_innermost_loop_index_counter". I mean "explicit is
> better than implicit", right?
> Maybe Fortran warped my brain, but I just don't see the benefit
> here. --
Oh, 'ix' would be fine. Single-letter loop counters are also semi-
fine if that is in fact their only use. It too-frequently happens
that at some point the handy 'i' identifier is used outside the
loop (for another placeholder), and its value is tromped by an
intervening loop. Not terribly difficult to discover, but then
what? When you're maintaining code, even a two-character index is a
*lot* easier to find in source code and replace as needed.
More information about the Python-list