3 ms·
I don't have any particular feelings toward one or the other (it is a convention, get over it), but I think that zero-based indexing is just an artifact of C th
by disconnected 9y ago
I don't have any particular feelings toward one or the other (it is a convention, get over it), but I think that zero-based indexing is just an artifact of C that stuck around.
In C, the array syntax is "mostly" just syntactic sugar for pointer arithmetic.
When you do "a[n]=value;" this is equivalent to "*(a+n) = value;". To get the nth cell of an array, you just add "n" to your base pointer "a".
Array indexing, therefore, is consistent with the pointer arithmetic.
That said, and funnily enough, Fortran, which is much older than C, has 1-based indexing (by default, but you can configure 0 based indexing, if I remember correctly).
- pvg 9y agoZero based indexing is not a C artifact. Here's Dijkstra writing about it in '82: https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/E...
- Bromskloss 9y agoNote how, in the PDF version [0], Dijkstra numbers the pages starting on zero (handwriting, upper right corner), but whoever created the PDF disregarded its message and did numbering starting on one (lower right corner). :-) [0] https://www.cs.utexas.edu/users/EWD/ewd08xx/EWD831.PDF https://www.cs.utexas.edu/users/EWD/ewd08xx/EWD831.PDF Edit: Fixed link. Hacker News apparently doesn't understand the delimiting of a URL with "<" and ">". >-( https://tools.ietf.org/html/rfc3986#appendix-C https://tools.ietf.org/html/rfc3986#appendix-C
- Avshalom 9y agoThere's the very real possibility that zero based indexing is in fact a Yacht Racing artifact. http://exple.tive.org/blarg/2013/10/22/citation-needed/ http://exple.tive.org/blarg/2013/10/22/citation-needed/
- Bromskloss 9y ago> The social reason is that we had to save every cycle we could, because if the job didn’t finish fast it might not finish at all and you never know when you’re getting bumped off the hardware because the President of IBM just called and fuck your thesis, it’s yacht-racing time. I don't buy it. Wouldn't people want their programs to run fast regardless of this?
- CyberDildonics 9y agoIn C arrays are given an offset to the pointer, not an index, that is why they start at 0.