7 ms·
Roberto Ierusalimschy has an interesting perspective on the zero vs. one concept: "Because people count from one, not zero. We do that in kindergarten, in mus
by LeafStorm 15y ago
Roberto Ierusalimschy has an interesting perspective on the zero vs. one concept:
"Because people count from one, not zero.
We do that in kindergarten, in music, when starting a race, when drawing up an agenda, everywhere. One, two, three, etc have their counterparts in every known language on earth.
Zero, on the other hand, is an advanced concept. Humanity could prove that sqrt(2) is not a rational number centuries before anybody thought that a symbol for zero might be useful.
A harder question would be "why do arrays in some other languages count from zero not one?" The answer for C is a good one: "so that * (A+k) and A[k] mean the same". For Python, the answer seems to be "because it's that way in C"."
And:
"Currently, many languages are 0-based due to influence from C. Ironically, none of them share the reason that made C 0-based (where a[e] means * (a+e))."
(EDIT: I had to add spaces after the stars to prevent HN from italicizing a huge block of text.
- oxtopus 15y agoMeanwhile, some people do count up from zero. At least in numbering floors in a building. I know in Europe and other parts of the world the ground floor is the zeroth floor, and it goes up from there.
- LeafStorm 15y agoYeah, a lot of the buildings at my university are numbered that way. But not even in Europe would one count a stack of paper as "zero, one, two, three..."
- dkersten 15y agoNumerically, yes, but nobody calls it a "zeroth" floor. Rather, its "ground", "first", "second" (or G, 1, 2, 3...) so while ground is equivalent to zero, nobody actually says (or thinks) zero. At least, nowhere I've been.
- inportb 15y agoSo let's just call it the "ground" index. G = ground = 0; A[G], A[1], A[2], ...
- sqrt17 15y agoWhere I work, rooms on the 1st floor have numbers like 1.01, 1.02 etc., on the ground floor it's 0.01, 0.02 etc., and in the basement it's -1.01, -1.02 etc. This is confusing for some people (unfamiliar with the situation), who need to go to a number in the basement but consistently turn up two floors higher.
- Goladus 15y ago> in music Music uses both systems. A chromatic approach uses a 0-indexed system while the classical diatonic scales and intervals are indexed at 1. A perfect 5th is a chromatic interval of 7 semitones. 1-do(0) 2-re(2) 3-me(4) 4-fa(5) 5-sol(7) 6-la(9) 7-ti(11) The question is whether it's more useful to count the notes that appear and label them with numbers, or to measure the difference between them.
- fuzzythinker 15y agoAnd Japanese don't seem to even have a word for that until they "borrowed" it.
- CJefferson 15y agoI often find 0-based indexing sneaking into other places too. For example, imagine I want to fake an nm 2d matrix M with an array A, with nm elements Then with 0-indexing, M[i][j] is stored at A[im+j]. With 1-indexing, M[i][j] is stored at A[(i-1)m+j].
- zvrba 15y agoI consider _counting_ and _indexing_ being two different concepts. In C, you declare int a[5], where 5 is the array size (element _count_), but its _indices_ run from 0 to 4. (Indeed, an array of size n can be also viewed as a _function_ with domain [0,n-1].)