by LeafStorm · 15y ago · 0 comments
"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.
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.
G = ground = 0;
A[G], A[1], A[2], ...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.
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].