

Where to start counting, 0 or 1? - joseakle

My hypothesis:
It's more usual to start with 0 when counting steps and with 1 when counting things.<p>Maybe that's why programmers start with 0, they usually count steps.
Age also starts at 0, nobody is born being 1 year old, although we are living our 1st year of life.
Races also start at 0.
When you want to know how many eggs are in the basket it makes little sense to say, oh i have an empty basket, 0 eggs, let's add some, now i have 1 egg, 2 eggs, etc.
======
dkokelley
When my littlest brother was learning to count, he would count the first
object twice (0, 1) then continue as normal.

Honestly, it depends on the situation, and I think you got it right. Things
start at 1, steps start at 0.

But starting at 0 presents a problem. If I have a set of stairs with 5 steps,
I either count the ground or the landing in my steps but never both. If I want
to get to the middle (3rd) step, if I'm at the bottom I just count 1, 2, 3
steps and I'm there, but if I'm at the top I only count 2 steps down. There
are really 6 positions I could be, but only 5 steps. You guys may have this
down, but it still trips me up sometimes.

------
blgraves
Age starts at 1 in some countries. I know this is the case in both Taiwan and
the Philippines, not sure where else. Someone who is 10 in the U.S. would be
considered 11 there.

~~~
edgarjph
With computerized registries, age surely starts at zero, as in zero year and
so many months. With rounding, age 1 will start after the sixth month.

For children's growth status tracking, the UN has a method in computing for
children's age and have been localized. I have used the Philippine reference
and age is computed in months. There is a 0 month age.

Culturally, I would presume you might be referring to parts of the Philippines
where people start counting age at one. I have never heard of this. We
celebrate the first birthday the usual way: one year after birth.

~~~
patio11
_With computerized registries, age surely starts at zero_

Except that, by convention, in China what you consider zero is already "0
years 9 months".

Its similar to describing the epoch time to my colleagues. You know, epoch
time: the number of seconds which have passed since midnight (GMT) on January
1st of the 45th year of the Showa era.

Incidentally, you want to have some fun in outsourcing? Try convincing your
Indian outsourcing team that it is Very Bloody Important that their code
account for the edge case when the last day of one era and the first day of
another era fall on the same day of the Western calendar. ("The data are
passed in as strings, the strings are always in the same format, why can't we
use string compare? It saves the conversion into a date." "That is premature
optimization and will introduce a bug for the following dates:..." "There's
only a few of them!")

~~~
edgarjph
That was what I meant when I said zero is zero years and so many months. Using
integers (or even decimals) and without rounding, 0 years and 9 months is
really zero. One will start 12 months (or the number of months the calendar is
using) after the date of birth.

Edge cases, I would estimate, would account for 30% of a program's logic. When
doing the first cut, I classify those as exceptions: abnormal values that
generate, well, exceptions.

Time-bound edge cases are abundant, especially in financial apps. End of
periods, beginning balances, ending balances.

Other edge-case values are max and minimum values, limits of whatever sort.
And these don't include limits of systems, like how many times a stored
procedure can be dropped and recreated, that are not commonly known or just
ignored hoping the app will hold before the longint limit will be reached.

------
trjordan
Dijkstra argues 0.

[http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EW...](http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html)

------
rubentopo
In my opinion, convention means nothing.

Do what makes sense according to the problem you're solving.

