Lower bounds of lists

Alex Martelli aleaxit at yahoo.com
Fri Mar 2 04:34:52 EST 2001


"Chris Gonnerman" <chris.gonnerman at usa.net> wrote in message
news:mailman.983493962.23590.python-list at python.org...
    [snip]
> > It seems an odd choice, as humans count from one, and Python in
> > other respects seems quite logical and well thought out.
>
> Humans count from 1.  Hackers count from 0.

Zero proved an elusive concept in the history of the human race
for many thousand of years -- that's why arithmetic lagged for
so long behind other disciplines such as geometry.  Fortunately,
somewhat over a thousand years ago, some Indian theoreticians
at last came up with the concept of zero (helped, no doubt, by
the crucial role that Nothingness plays in their philosophies --
just as much as earlier Greek thinkers were hampered by
Parmenides' insistence that "Not-Being does not exist nor
cannot it exist").

Arabs took it up from them, then Italians from Arabs, then the
rest of Europe -- with decimal notation for numbers, and one
other key innovation, double-entry bookkeeping, arguably an
Italian invention (but it would never have flown without
decimal-notation numbers to ease the sums:-).  The whole
Renaissance, and, later, the flourishing of modern science,
were enabled by the introduction of Zero, and the various
related technologies (e.g., the explosion in finance, banking,
entrepreneurship, which marks the late Italian Middle Ages and
directly ushered in the Renaissance, had double-entry
bookkeeping as one of its key enablers).

Zero works better -- it better reflects underlying arithmetic
reality.  The tens of thousands of years it took human beings
to come to terms with it confirms it's hard for our minds -- just
as, say, reading and writing, or even more, as it got another
few millennia's delay.  Fortunately, memes do spread -- these
days, we get socially exposed to Zero right from our birth,
and so, fortunately, many of us get a precious leg up -- enough
to overcome our biological limitations in the matter.

I agree with Python's design decision in this regard, to cater
more for underlying arithmetical realities than for biological
limitations of human beings.  If Python was designed around the
10th Century, then "Zero" might well be considered far too new,
radical, and unproven a concept for widespread consumption, no
doubt; but, thankfully, a thousand years' worth of history has
widely ameliorated things in this regard, so that a programming
language CAN now afford to better match undelying reality.



> > Starting lists at zero also seems to have had ripple effects,
> > such as
> >
> > range(1,100) giving (1, 2, 3, ... , 99)
>
> This gives me headaches sometimes also; JavaScript does similar things.

"Lower-limit-included, Upper-limit-excluded" is a very good
mantra.  It has all sorts of useful invariants, such as
range(X,Y) having Y-X items rather than, say, Y-X+1 -- that
'+1' would give far worse headaches and off-by-one errors.


Alex






More information about the Python-list mailing list