Python "why" questions
patentsvnc at gmail.com
Fri Aug 13 17:27:50 CEST 2010
> ... However, the killer reason is: "it's what everybody
> else does.
If this were really true, lists would be 1-based. I go back to
WATFOR; and Fortran (and I believe Cobol and PL/I, though I'm not
positive about them) were 1-based. (Now that I think about it, PL/I,
knowing IBM, could probably be set to use either) Back then, everyone
else was doing 1-based lists.
In my opinion, the reason lists are 0-based started with a lazy
programmer who decided that his own comfort (using 0-based addressing
at the machine level and not having to translate the high-level 1-
based language index into a low-level 0-based index) was paramount
over teaching the language and having it make sense in the real
world. After all, not even Brian Kernighan thinks books start on page
0. I'm not singling out C in this case because it is a relatively low-
level language for low-level programmers and 0-based lists make
perfect sense in that context. But then every compiler/interpreter
programmer after that stopped caring about it.
I smile every time I see the non-nonsensical sentence "The first
thing, therefore, is in thing" in a programming language learning
book or tutorial. I laugh every time I hear someone defend that as
common sense. Every three year old watching Sesame Street knows
counting things starts with '1', not '0'. When you were three and you
counted your blocks, you started with '1', not '0'. The whole rest of
the world understands that implicitly, even if their counting starts
'1', '2', 'many'. 0-based lists are NOT common sense. They only make
sense to the programmers of computer languages, and their fanbois.
There may be loads of reasons for it, but don't throw common sense
around as one of them.
More information about the Python-list