Why do programmers start counting at zero?

Interesting read: http://exple.tive.org/blarg/2013/10/22/citation-needed/

"The fact of it is this: before pointers, structs, C and Unix existed, at a time when other languages with a lot of resources and (by the standard of the day) user populations behind them were one- or arbitrarily-indexed, somebody decided that the right thing was for arrays to start at zero.

So I found that person and asked him."

That drives me nuts about many “modern” languages.

Better yet, let me decide what to start at. Maybe have it default to 0, but use something like “Option Base” in VB where I can set arrays to start at 1, if I like.

An interesting read - thanks!

Excellent read.

Interesting read. Of course, “because C…” is a no less valid answer. Both reasons go back to the underlying architecture and machine code.

Easy math decided it for the computer engineers creating machine code, that knowledge migrated to higher languages. If we created a language using a one based index, the internal math would need to add a “DEC INDEX” instruction before calculating the position of a array item in the memory at runtime or decreasing index values at compile time when possible. I’ve programmed machine code in the 80’s and needed to do all that math by myself using 8 bit instructions. Zero based arrays is the “natural” way for a computer doing his job (base_address+displacement).

The thoughts of Prof. Dr. Edsger W. Dijkstra about the matter in 1982:

Great read and some very interesting history
Some I knew of from taking a history of computing course many years ago from the guy who was the ACM Chair of the History Of Computing at the time
There’s as much mythology about things in Comp Sci as anywhere

And those damned ferrite core things are heavy as hell - the ACM fellow had us move a 4K one he had acquired …
OMG !!!
I think we all had sore backs for a week

Isn’t the problem because some things start at 0 and other start at 1 ?

Or an example from the “real” world:
When you enter a building at ground level, are you on the 1st floor?

[quote=170280:@Gerd Wilmer]Or an example from the “real” world:
When you enter a building at ground level, are you on the 1st floor?[/quote]

Ah now that depends on where you are! If you’re in the UK then you are on the ground floor. The first floor is the first one above ground level… so the second floor if you like :wink: I live in a first floor apartment and it drives my non-British wife mad as she’s used to the first floor being the ground floor.

And in some countries buildings have no 13th floor. Imagine an array…

yes, mine only has 2 :wink:

New to me :stuck_out_tongue:

Same vein, different superstition : http://en.wikipedia.org/wiki/Tetraphobia

And then there’s the Mertin Flemmer building, which has a 7 1/2 floor. :wink:

Some building I’ve been in (actually a lot of the ones where i used to work) simply labelled them “Ground” , 1, 2, 3, etc

In Brazil we have elevator’s buttons like T, 1, 2, 3… or 0, 1, 2, 3 (T is for Trreo, at the level of the terrain, ground).
One is nonsensical for 99.999% of the real starts (to be true I can’t imagine some measure starting at 1). The 10 numbers are 0,1,2,3,4,5,6,7,8 and 9. A newborn does not start 1 year old for instance, he needs to live 12 months after starting living in his zeroth day, in his zeroth year, to reach this status. :slight_smile:

And yet some cultures do exactly that. You are born in your first year. 12 months later, you turn 2.

AND, in sesame street, they say:
1, 2, 3, 4, 5,
6, 7, 8, 9, 10