4 ms·
To expand on my comment below, I assumed zero-based indexing was a natural extension from binary. When using bits (in this case three bits) as a representation,
by ruraljuror 10y ago
To expand on my comment below, I assumed zero-based indexing was a natural extension from binary. When using bits (in this case three bits) as a representation, you start with 000. Naturally that would be referred to as 0.
- ben_bai 10y agoI just think of it as offsets. Array X at offset 0, which is the first entry.
- zAy0LfpBZLC8mAC 10y agoWell, yes, but: That ultimately is also an arbitrary definition, in a way. You could also build a computer where 000 would represent the integer 1. And the reason why that is not the case, but 000 instead represents the integer 0 is essentially what I said above: It's simpler to build a binary computer that computes 000 + 000 = 000 and 000 + 001 = 001 and 001 + 001 = 010, instead of one that computes 000 + 000 = 001 and 000 + 001 = 010.
- JadeNB 10y agoIn this sense everything is an arbitrary definition—which is true, but makes arguments about naming sort of useless. (Perhaps the correct answer is that they are, and this is just revealing that ….) At a certain point the argument, if it is to be at all productive, must become not "what is the one and only true way to do this?"—there never is one for naming—but "what are some other conventions that might guide us to a well determined consistent, rather than arbitrary, convention in this case?"
- zAy0LfpBZLC8mAC 10y ago> In this sense everything is an arbitrary definition Hmm, no, not really. While definitions are, indeed, by definition arbitrary, different concepts are of different usefulness, and as such, definitions that use more useful concepts can reasonably be considered better definitions of given terms. There is no such advantage in using the binary 000 to represent the first index, though, except in so far as it results from the binary 000 representing the neutral element of addition, which corresponds to the natural number 0. The latter is the part that's actually not arbitrary. > there never is one for naming Well, the whole point kindof is that it's not about naming, but about arithmetic. If you only want to name stuff, you can use strings and hash tables, or letters of the alphabet, or whatever other set of symbols that you can come up with, it's really to a large degree a matter of taste. But there is a distinctive feature of arrays vs. other collection data types: You can do arithmetic on its indices. And arithmetic with a number type that doesn't have a zero is braindead.