EDIT: and I consider this to be all the proof I ever need: http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EW...
EDIT: and I consider this to be all the proof I ever need: http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EW...
0-based arrays are easier for computer folks who occasionally have to implement the code that translates 'a[i]' into a memory access. 1-based is easier for physicists and mathematicians who were subscripting variables before there were computer implementations to worry about and had a pile of literature already written using that idiom. It's just a clash of conventions.
I haven't made an indexing-based error in over 10 years, and the only reason I ever had it before was from having to switch back and forth between C and VB6 years ago.
http://www.cs.utexas.edu/~EWD/transcriptions/EWD08xx/EWD831....
In Julia, the natural numbers 2, 3, ..., 12 are expressed as 2:12 and the empty range starting at 2 is expressed as 2:1.
N = rows(data)
for i in 1:N
blah
So even though 1:0 may seem not unnatural, it actually reads perfectly in most code.You're fighting a straw man; that isn't the argument. 1-based indexing is elegant for many mathematical uses. Technical computing often implements algorithms that are best written down using mathematical notation. In such a case the largest conceptual difficulty is not the origin of the index but the successful translation of the algorithm. To minimize the possibility of error, the original indexing (especially when it involves nontrivial mathematical maps) is often preserved.
> Dijkstra makes all of the convincing arguments for why 0-based is better than 1-based.
He essentially makes only one point. Namely that, when using 0-based indexing we can easily determine the length of a sequence by only its upper index. Though it's not a profound observation since the index bias is zero, it often gets treated as such.
Either way, it's a convention. A competent programmer should be able to handle any well-specified indexing convention (including those starting at negative indices). Different circumstances will confer different benefits on different conventions, and you should use the one that's most appropriate for the task at hand rather than religiously promoting The One True Way (TM).
I don't see how you could have indexing from the tail being internally consistent if the arrays are 1-indexed.
1 and end for the first and last, 2 and end-1 for the second and second to last, and so on.
"And that’s the most coherent argument I can find; there are dozens of other arguments for zero-indexing involving 'natural numbers' or 'elegance'[2] or some other unresearched hippie voodoo nonsense that are either wrong or too dumb to rise to the level of wrong."
I still believe this is the only time EWD's work has ever been referred to as "unresearched hippie voodoo nonsense".
Is this the same Mike Hoye who hacks Zelda?[potato]
[potato] http://www.huffingtonpost.com/2012/11/16/mike-hoye-hacks-zel...
[2] http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EW...
History can inform the argument, but history does not make the argument. Observing the effects of 0-vs-1-based indexing in existing languages can give us data about the pragmatic effects of either decision. But the precise chain of cause-and-effect of decisions made in the 1960s in an environment where both the hardware and social structures around computing were radically different than they are now is really not that relevant to the question of which approach is better overall.
The article is also snide and openly insulting to nearly everybody (including Dijkstra); combined with its lack of a convincing argument, this article does not deserve to be treated as a credible position piece in support of 1-based indexing.