30 ms·
Calculating these multidimensional indexes seems to be the major or even the only reason I've ever come across for having 0-based arrays. But it's a pretty big
by averagewall 10y ago
Calculating these multidimensional indexes seems to be the major or even the only reason I've ever come across for having 0-based arrays. But it's a pretty big reason.
- eru 10y agoHmm, I don't know directly about arrays. But for indexing into a linked list 0-based just seems to make the mest sense---if you interpret the index as "how many pointer do I have to chase?". And giving arrays the same treatment then seems reasonable for consistency? I always saw 0-based indices as offsets. Ie like their C interpretation, where a[i] is defined to be the same as * (a+i), not the less natural *(a+i+1). But I can see some points for 1 based indexing, too. (Anecdote from university: the math faculty had a building that started numbering the ground floor as -1. Perhaps just to one up (or is that one down?) the computer scientists who always feel smug about counting from 0.)
- FireFly 10y agoThat anecdote reminds me of the classic solution to the zero-versus-one-indexing fights in the Lua community: clearly the solution is to compromise! :) http://lua-users.org/lists/lua-l/2006-05/msg00281.html http://lua-users.org/lists/lua-l/2006-05/msg00281.html
- Double_Cast 10y ago"multidimensional indexes" sounds like something obscure and rarely used. But plain-old Decimals are a special case of this, and people use Decimals every day.