Re:Edsger Dijkstra's note on starting array indices at 0 (pd...
by jleader on Tuesday June 21, 2011 @07:55PM
(#2680924)
But indexing is not counting. It bears some similarity to measuring, though. If you look at a ruler, does it begin with a "1"? Or does it have a "1" one unit from the beginning?
Re:Edsger Dijkstra's note on starting array indices at 0 (pd...
by stan_rogers on Tuesday June 21, 2011 @09:46PM
(#2681279)
Indexing is only "not counting" when you're working with a base address and an offset. In most languages, that's only an "under the hood" reality; the programmer is neither interested in, nor has direct access to, the bitly goodness underlying the array (or what have you). It's just a bunch of slots, and when you want to put something into (or take something out of) the first slot, then the natural ordinal is "first", not "zeroth". We're just used to a different way of doing things; it doesn't make any more sense to anyone, except by convention.
Re:Edsger Dijkstra's note on starting array indices at 0 (pd...
by forkandwait on Tuesday June 21, 2011 @11:34PM
(#2681591)
It IS counting when it measures discrete elements, and it is measuring when it measures distance from a boundary. Discrete sets and continuous sets are very different beasts, and some of the mix-up here seems to be from ignoring their differences.
Re:Edsger Dijkstra's note on starting array indices at 0 (pd...
by StavrosK on Tuesday June 21, 2011 @07:03PM
(#2680777)
> arrays starting at 0―how natural!
Better than starting at pi; that would be irrational.
Re:Edsger Dijkstra's note on starting array indices at 0 (pd...
by viraptor on Tuesday June 21, 2011 @05:17PM
(#2680461)
You might change it again to "no programmer of language without direct access to memory pointers". Then again, even that would be hard to prove. I definitely didn't see anything wrong with starting at 0 and it made perfect sense for C arrays.
Re:Edsger Dijkstra's note on starting array indices at 0 (pd...
by ralfd on Wednesday June 22, 2011 @06:51AM
(#2682562)
Think about that:
A clock starts at zero. A day has 24 hours but there is not a twenty-fourth hour. Midnight is 0:00.
Re:Edsger Dijkstra's note on starting array indices at 0 (pd...
by gnosis on Wednesday June 22, 2011 @09:44AM
(#2683043)
Clocks are a relatively recent invention.
Re:Edsger Dijkstra's note on starting array indices at 0 (pd...
by ralfd on Wednesday June 22, 2011 @11:48AM
(#2683656)
In fact Clocks are one of the oldest inventions of the human mind. 4000 years ago in Babylon water clocks (clepsydra) were used. Also in old China. http://www.nist.gov/pml/general/time/images/water_1.gif
There is a 2050 year old Horologia tower in Athen ("Tower of the Winds"):
"This structure tracked a 24-hour day using both sundials and mechanical hour indicators"
Re:Edsger Dijkstra's note on starting array indices at 0 (pd...
by gnosis on Wednesday June 22, 2011 @03:45PM
(#2684807)
Humans have been around for more than 200,000 years (up to 2.5 million years, depending on how you define the term "human"). So even 4,000 years ago is relatively recent on the scale of human history.
Re:Edsger Dijkstra's note on starting array indices at 0 (pd...
by Jacquass12321 on Tuesday June 21, 2011 @05:11PM
(#2680442)
I'd disagree with your last statement. I enjoy the mathematically simplicity of the address into your array being pointer+size(index) as opposed to pointer+size(index-1). Now I will agree that it's probably because of too much math, but it just makes sense that if I want to drop out a term I can multiply it by zero. It's like finding roots of polynomials.
Re:Edsger Dijkstra's note on starting array indices at 0 (pd...
by beaumartinez on Tuesday June 21, 2011 @05:18PM
(#2680466)
I actually meant programming student, as in, student learning programming for the first time―naturally, once we reach a certain level of proficiency, more of the esoteric concepts seem intuitive to us; I've edited my post accordingly.
You're right that it is convenient that the address of an item is first index + current index * index size in memory, but things like that comes at a cost of making indeces completely unintuitive.
Re:Edsger Dijkstra's note on starting array indices at 0 (pd...
by to3m on Wednesday June 22, 2011 @10:07PM
(#2686331)
You're (probably) right, and no student learning programming for the first time thought that starting array indexes at zero was a natural idea.
That is because they are learning it for the first time.
Another way of putting that might be that they don't know a single thing about the subject ;)
A list of twenty items has a twentieth item.
Dijkstra is far too mathematical with this―no student learning programming for the first time (edited: changed from programmer) in the world ever thought "arrays starting at 0―how natural!".