From: Roald de Vries on
On Aug 7, 2010, at 3:53 PM, D'Arcy J.M. Cain wrote:
> On Sat, 7 Aug 2010 15:37:23 +0200
> Roald de Vries <downaold(a)gmail.com> wrote:
>>> Would said beginner also be surprised that a newborn baby is zero
>>> years
>>> old or would it be more natural to call them a one year old? Zero
>>> based counting is perfectly natural.
>>
>> A new born baby is in his/her first year. It's year 1 of his/her
>> life.
>> For this reason, also "the year 0" doesn't exist. From the fact
>> that a
>> baby can be half a year old, you derive that arrays should have
>> floats
>> as indices?
>
> No. You are giving me math and logic but the subject was common
> sense. Common usage counts ages as years with the second year called
> "one year old" so zero based counting is common. We don't tell Aunt
> Martha that little Jimmy is in his third year. We say that he is two
> years old and Aunt Martha, a non-programmer, understands exactly what
> we mean. Using one-based counting (first year, second year, etc.)
> would be the unnatural thing, would confuse Aunt Martha and make her
> spoil her apple pie and no one wants that.

My point is that "0" in "Jimmy is 0" doesn't play the same role as in
"item 0 of a sequence".
From: Steven D'Aprano on
On Sat, 07 Aug 2010 08:54:28 -0400, D'Arcy J.M. Cain wrote:

> On Sat, 07 Aug 2010 13:48:32 +0200
> News123 <news1234(a)free.fr> wrote:
>> It makes sense in assembly language and even in many byte code
>> languages. It makes sense if you look at the internal representation of
>> unsigned numbers (which might become an index)
>>
>> For a complete beginner common sense dictates differently and there
>> might be confusion why the second element in a list has index 1.
>
> Would said beginner also be surprised that a newborn baby is zero years
> old or would it be more natural to call them a one year old? Zero based
> counting is perfectly natural.

There's nothing natural about saying that a baby is zero years old. A
newborn baby is "a newborn baby", then it's "one day old", "two days
old", ... "one month old", "two months old", ... "one year old".

In any case, we're discussing *ordinals*, not cardinal numbers. The
ordinals in common English are first, second, third, ... but in computing
frequently zeroth, first, second, third, ...

There is a reason why mathematicians describe the integers 1, 2, 3, ...
as the "Natural Numbers". It took thousands of years of human
civilization before people accepted that zero was a number. In fact, for
the ancient Greeks, one wasn't a number either. We still reserve the term
"a number of X" to refer to more than one X, and would feel cheated if
somebody offered us a number of gifts and then gave us only a single one.
"Number" refers to a plurality, and one is singular.

According to Euclid, one was the monad, the indivisible unit from which
the numbers were formed. As late as 1537, the German mathematician Jacob
Kobel wrote "1 is no number, but it is a generatrix, beginning and
foundation for all other numbers".

In short, there's nothing natural about counting numbers at all, let
alone whether we should start at 0 or 1.



P.S. I don't know if I should be gratified or disappointed that nobody
has yet quoted Stan Kelly-Bootle:

"Should array indices start at 0 or 1? My compromise of 0.5 was rejected
without, I thought, proper consideration."




--
Steven
From: Thomas Jollans on
On 08/07/2010 03:38 PM, Steven D'Aprano wrote:
> On Sat, 07 Aug 2010 14:00:59 +0200, Thomas Jollans wrote:
>
>> On 08/07/2010 05:05 AM, Default User wrote:
>>> >From "the emperor's new clothes" department:
>>>
>>> 1) Why do Python lists start with element [0], instead of element [1]?
>>> "Common sense" would seem to suggest that lists should start with [1].
>>
>> As others have pointed out, there is a nice argument to be made for
>> zero-based indices. However, the killer reason is: "it's what everybody
>> else does."
>
> I'll have you know that there are still some Pascal programmers in the
> world, thank you.
>
>
>
>> As it stands, the only perceived problem with zero-based
>> indices is that it's one of the many tiny confusions that new
>> programmers face. On the other hand, it's the way nearly every other
>> popular programming language does it, and therefore, it's the way almost
>> every programmer likes to think about sequences.
>
> It didn't take me long to get used to thinking in zero-based indexes, but
> years later, I still find it hard to *talk* in zero-based indexes. It's
> bad enough saying that the first element in a list in the zeroth element,
> but that the second element is the first makes my head explode...

zeroth
oneth
twoth
;-)

(element no. one is a better way of pronouncing it.)

>
>
>> Also, it has the nice property that, for an infinite sequence, every
>> integer makes sense as an index (in Python).
>
> Er, what's the -1th element of an infinite sequence?

well, it's the first from the other end. The infinite bit is in between,
thank you very much. ;-)

From: Nobody on
On Sat, 07 Aug 2010 09:53:48 -0400, D'Arcy J.M. Cain wrote:

>> A new born baby is in his/her first year. It's year 1 of his/her life.
>> For this reason, also "the year 0" doesn't exist. From the fact that a
>> baby can be half a year old, you derive that arrays should have floats
>> as indices?
>
> No. You are giving me math and logic but the subject was common
> sense. Common usage counts ages as years with the second year called
> "one year old" so zero based counting is common. We don't tell Aunt
> Martha that little Jimmy is in his third year.

Apparently, the Japanese used to (before they started adopting western
conventions). I.e. ages were given as "in his tenth year" (meaning nine
years old).


From: Nobody on
On Sat, 07 Aug 2010 13:48:32 +0200, News123 wrote:

>> "Common sense" is wrong. There are many compelling advantages to
>> numbering from zero instead of one:
>>
>> http://lambda-the-ultimate.org/node/1950
>
> It makes sense in assembly language and even in many byte code languages.
> It makes sense if you look at the internal representation of unsigned
> numbers (which might become an index)

It also makes sense mathematically. E.g. for an MxN array stored as a
1-dimensional array, the element a[j][i] is at index

j * N + i

with zero-based indices but:

(j-1) * N + (i-1) + 1
= j * N + i - N

with one-based indices.

IOW, if a language uses one-based indices, it will inevitably end up
converting to and from zero-based indices under the hood, and may end up
forcing the user to do likewise if they need to do their own array
manipulation.