4 ms·
I have to offer a counter view to this. Using letters of the alphabet as an analogy isn't accurate to me. Each letter we accept as an element... so a true ana
by 51Cards 10y ago
I have to offer a counter view to this. Using letters of the alphabet as an analogy isn't accurate to me. Each letter we accept as an element... so a true analogy would be to put a Space as the first character of the alphabet, to indicate the absence of a letter.
Zero indicates the absence of a value in our numbering system. If I have a single apple, I have 1 Apple, not 0 Apples. Thus if I have 1 element in an Array I have element[1], not element[0]. It is more natural for us to use numbers not by their cardinal position in a set, but by their inferred value... because they represent quantities.
I am one of those who feels the confusion around zero bounded indexes leads to countless issues because it is counter-intuitive to how we use numbers in real life. I agree it is beaten into developers that this is how is should be, but to me we would have been further ahead to let developers accept what comes intuitively.
- zAy0LfpBZLC8mAC 10y ago> I have to offer a counter view to this. Using letters of the alphabet as an analogy isn't accurate to me. Each letter we accept as an element... so a true analogy would be to put a Space as the first character of the alphabet, to indicate the absence of a letter. So, you would say that "A" is not the first element of the alphabet or that "0" is not the first cardinal number? > Zero indicates the absence of a value in our numbering system. You are utterly confused. If I have an account balance of zero, that indicates an absence of a value? How is zero mathematically any different then +1000 or -1000 that justifies making it a special case? > If I have a single apple, I have 1 Apple, not 0 Apples. Thus if I have 1 element in an Array I have element[1], not element[0]. You are mixing up ordinal and cardinal numbers. > It is more natural for us to use numbers not by their cardinal position in a set, but by their inferred value... because they represent quantities. There is no such thing as a "cardinal position", positions are ordinal, cardinality describes sizes. > I am one of those who feels the confusion around zero bounded indexes leads to countless issues because it is counter-intuitive to how we use numbers in real life. Nope, what leads to problems is that people don't understand the difference between cardinal and ordinal numbers. You cannot fix that by changing the first index, all that causes is a shift to different bugs. Including stuff like equating zero with the absence of a value.
- thomnific 10y agoI agree with you and also with the person you replied to. But more generally -- is it fair to say that cardinality describes size as opposed to quantity? If you go with the quantity concept instead then 1-based numbering makes sense and agrees with ordinary usage. (Disclaimer: I used to hate 1-based indexing, for reasons similar to what you are saying, but I'm brainwashed by R these days and now rather like it.)
- zAy0LfpBZLC8mAC 10y ago> is it fair to say that cardinality describes size as opposed to quantity? Nope, size is equivalent to quantity in this context. But ordinals describe position in an order as opposed to size/quantity. If you want to connect them mathematically, you would usually map a scale to a quantity measure, where the first unit position on the scale is the zero-position, the second unit position is the one-position, and so on--so, a quantity of size three units reaches from the position 0 on the scale to the position 3 on the scale. > (Disclaimer: I used to hate 1-based indexing, for reasons similar to what you are saying, but I'm brainwashed by R these days and now rather like it.) Well, it doesn't matter unless you have to to arithmetic with the indices, you might as well label them with letters from the alphabet, so if you don't need that, it's simply a matter of getting used to it. But in general-purpose programming languages, array indices are often computed, and 1-based indexing is as sensible there are having an integer type that doesn't have a zero. It's not that you cannot work with it, but it makes things unnecessarily complicated.
- ivanhoe 10y ago> How is zero mathematically any different then +1000 or -1000 that justifies making it a special case? Zero is actually always a special case in math, specially in algebra, the only number where division by it is not defined. > Nope, what leads to problems is that people don't understand the difference between cardinal and ordinal numbers. Actually, by Von Neumann definition of ordinals, ordinal 0 represents an empty set, thus it's equivalent of null, not single element set. So strictly mathematically speaking for non-empty sets we should use ordinals starting at 1. But using zero-based indices is just a matter of convention, so lets not make a big philosophy out of it...
- 91bananas 10y agoNever thought about it in terms of what the value of the number actually meant. You make an interesting argument.
- deleted 10y ago[deleted]
- caf 10y agoI am one of those who feels the confusion around zero bounded indexes leads to countless issues because it is counter-intuitive to how we use numbers in real life. What's counter-intuitive to me is that we habitually call the second floor in a building the "first floor"!