Earlier quoted context omitted.
Except 1-based indexing is what we use in normal language. We don't use "zeroeth" or "player (number) zero" etc. And the word "first" is shortened to 1st etc. Personally I think we'd be better off if programming languages stuck to the same convention - off-by-1 errors aren't the hardest problems to deal with but they're still annoying.
Well: https://www.merriam-webster.com/dictionary/zeroth
Why do arrays start at 0?
541–550 of 702 posts
Re: Why do arrays start at 0?
#542Toddlers love this invariant.
Re: Why do arrays start at 0?
#543Earlier quoted context omitted.
> additional computational overhead at compile time, not runtime.
For constant addressing; for arr[i] = 2, you'll still need to subtract 1 from i with 1-based addressing when converting to machine instructions.
Re: Why do arrays start at 0?
#544Earlier quoted context omitted.
I would be fine with it all if 0-based was called "offset", with "index" reserved for 1-based. The element at offset 0 is the first element. Precision in naming is important.
Defining index as the element wise offset is a precise well formed definition/name. It's also a definition commonly used in math, through not always. It depends a lot of the area of mathematics and even the cultural context. The only reason we sometimes feel 0-index is wrong IMHO is because the english language describes entities in a sequence as 1st, 2nd, 3rd etc. But I wouldn't be surprised if there is some human l…
But it's less precise than offset and obviously introduces confusion. Whoever originated the term "0-indexed" should have just suggested we use a better word rather than keeping the inaccurate word (proven by the fact you're currently looking for a way to remove some confusion around the currently chosen word) and prefixing it with a digit, which itself is a confusing thing to do to an English word, thus adding to the confusing while subtracting none.
Re: Why do arrays start at 0?
#545Earlier quoted context omitted.
Defining index as the element wise offset is a precise well formed definition/name. It's also a definition commonly used in math, through not always. It depends a lot of the area of mathematics and even the cultural context. The only reason we sometimes feel 0-index is wrong IMHO is because the english language describes entities in a sequence as 1st, 2nd, 3rd etc. But I wouldn't be surprised if there is some human l…
Which floor is the first floor in your building? Depends which country your building is in, and more! My apartment building is 1,2… but my mall is G,M,1,2… (same country different architects). For many years I lived in Europe where it’s usually G,1,2… (where G can also be E or Fsz or whatever) and when I was in the US I had to remember that 1 is G, though L,2,3… is also common. City people live with index ambiguity a…
Confused me when I visited USA.
Re: Why do arrays start at 0?
#546If you think of arrays just as a kind of abstract list, then beginning at 1 makes much more sense. No one who looks at a to-do list at home talks about the 0th thing on their list to do. But the spacial nature of arrays makes starting at 1 confusing. After I take 1 step, I am no longer at my starting point. And cycling through arrays in code for me has a very similar feeling to taking actual physical steps through a data structure.
Re: Why do arrays start at 0?
#547Earlier quoted context omitted.
I think, in theory, it would work regardless of the starting address. As long as you don't try to access the invalid address (which you wouldn't assuming that it's starting in the index 1, you would always be accessing the first valid address)
In theory, it’s not guaranteed to work at all. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2310.pdf#p... (emphasis added): “In other words, if the expression P points to the i-th element of an array object, the expressions (P)+N (equivalently, N+(P)) and (P)-N (where N has the value n) point to, respectively, the i + n-th and i − n-th elements of the array object, _provided_they_exist” […] If both the pointer o…
Not that I would want to do it, I think zero-based addressing is not very taxing for the convenience of being closer to how we think of memory addressing.
Re: Why do arrays start at 0?
#548I don't quite understand the argument "0-based being easier for pointer arithmetic is nonsense because the language doesn't have pointers". Whether or not the language presents the concept of "pointer" to the user is independent of whether or not it uses pointers internally. And if it exposes arrays as a concept, it has to implement them somehow. The simplest possible implementation of arrays is having a start addres…
I would be fine with it all if 0-based was called "offset", with "index" reserved for 1-based. The element at offset 0 is the first element. Precision in naming is important.
Re: Why do arrays start at 0?
#549Lo and behold, it's written by the same author.