3 ms·
I think zero-indexing is appropriate for thinking in terms boundaries and distances from the start or edge of something. C indexes arrays from zero because you
by forkandwait 15y ago
I think zero-indexing is appropriate for thinking in terms boundaries and distances from the start or edge of something. C indexes arrays from zero because you have gone zero distance from the boundary of the contiguous memory chunk when you access the first element.
HOWEVER, when you are doing math, you more often think in terms of sets of cardinality N, with N=0 being an empty set. Also, the last 400 years of math has been written with one-indexing, so when you translate matrix formulas or summation notation into numpy, you have to dork around with -1 all the time, and it sucks. Matlab and R are both 1-indexed and it is the only thing that really makes sense when you are working with them.
I personally hate one-indexing, but 98% of what I do is data analysis and mathematical programming. If I was doing low-level (-ish) memory addressing, it would be a different story.
I thought Perl and Tcl and Python and Ruby just adopted zero-indexing by default from C, but now I see someone smart advocated for it explicitly (too bad he is wrong, at least part of the time)