A few times during discussion about programming, I reached a misunderstanding, caused by different views on how consecutive zero-based array elements are referred to using ordinal numerals. There seem to be two views on that:
a[0] = "first";
a[1] = "second";
a[2] = "third;
vs:
a[0] = "zeroth";
a[1] = "first";
a[2] = "second";
I always preferred the first, knowing that "n-th" element is "element of index n-1". But I was surprised how many people found that counter-intuitive and used the latter version.
Is one of those conventions more correct than the other? Which should I use during discussion or documentation to avoid misunderstanding?
I think the English meaning of the word "first" is unambiguous, and refers to the initial element of a sequence. Having "first" refer to the successor of the initial element is just wrong.
In cases where there might be confusion, I would say "the third element, at index 2".
The element index is pretty much language-dependent (e.g. C: 0, Lua: 1), whereas the fifth element is the fifth element, it's just the index that may be different ;)
I guess that's way too diffuse an answer...
In some languages, such as Pascal, you can specify the range of indexes explicitly. i.e.
var stuff : array[-3..3] of integer;
stuff[-3]
is still the first element in the array, not the negative third.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With