0-indexed decimal grid:
0 1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18 19
20 21 22 23 24 25 26 27 28 29
30 31 32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47 48 49
50 51 52 53 54 55 56 57 58 59
60 61 62 63 64 65 66 67 68 69
70 71 72 73 74 75 76 77 78 79
80 81 82 83 84 85 86 87 88 89
90 91 92 93 94 95 96 97 98 99
1-indexed decimal grid: 1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50
51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70
71 72 73 74 75 76 77 78 79 80
81 82 83 84 85 86 87 88 89 90
91 92 93 94 95 96 97 98 99 100The first year CE being "1" resulting in the new millennium starting at 2001 instead of 2000 also seemed idiotic, and the 1900s being referred to as "the 20th century" was something I always had to consciously compensate for. Numbering items starting at zero would have given us more elegant/less confusing ways to communicate those things.
Zero-based indexing makes things inherently simpler because it matches the way we write numbers (and becomes much more noticeable once you have more than one digit). It's not just an optimization for computers.
By AD 150, Ptolemy, influenced by Hipparchus and the Babylonians, was using a symbol for zero.
https://en.wikipedia.org/wiki/0#History
To keep it confusing: the traditional proleptic Gregorian calendar (like the Julian calendar) does not have a year 0 and instead uses the ordinal numbers 1, 2, ... both for years AD and BC. Thus the traditional time line is 2 BC, 1 BC, AD 1, and AD 2. ISO 8601 uses astronomical year numbering which includes a year 0 and negative numbers before it. Thus the ISO 8601 time line is −0001, 0000, 0001, and 0002.
https://en.wikipedia.org/wiki/Gregorian_calendar#Dual_dating
My kids' school also uses zero-based tables.
"Natural" is a very loaded and ambiguous term, best avoided if you hope to have sane discussions.
It's the difference between ordinal and cardinal numbers. In other words, counting and indexing.
https://news.ycombinator.com/item?id=5888459 (quoted here for convenience)
—————
Formally, ordinals start at zero too :-) [0]. We owe their latest definition to Von Neumann, but AFAIK, the former definitions were similar. [...snip...]
--
[0] This is meta-meta-contrarianism.
- The layman counts from 1
- The uptight programmer counts from zero, because Dijkstra said so (or so he thinks).
- The meta-contrarian (I used to be one) says fuck it, ordinals start at one.
- The meta-meta-contrarian reads Wikipedia[1], realizes he was formally wrong, and goes one step further in pedanticity, back to zero [0].
That being said, my brain prefers 1-indexing programming languages like Lua, Julia, R and Matlab...
[1] http://en.wikipedia.org/wiki/Ordinal_number
[0] Help! I'm stuck in a Boolean algebra[1][0]!
[1] http://en.wikipedia.org/wiki/Boolean_algebras_canonically_de...
[0] ... where xor is an addition that wraps around ...
I do not believe for a second that you taught them to count by holding up one finger for zero, two fingers for one etc.
Reminder that we're specifically talking about array indexing.
They will get confused because every day counting got it wrong. In a perfect world we would count fingers from 0.
ldr x, [addr, idx]
it just does sub t1, idx, #1
ldr x, [addr, t1]
If we're talking about C, accessing invalid/OOB indices is undefined and so if idx happens to be zero and unsigned, we'll overflow and hit something unexpected, which is fine.> It's not the reason you think. No, it's not that reason either.
Indexing is a language level concern, it has nothing to do with the generated code.
Unless you write machine code I guess.
IIRC, Visual Basic 6 took a why not both? approach to array indexing.
> These all point to one reason why 0-indexing might be preferred: it matches machine semantics more
To write 4 numbers (including zero) you only need two bits
To write 4 numbers if you avoid using the number zero, you need three bits If you extrapolate that a little bit, you'll realize that you'll need two bytes (1 Byte + 1 bit from another byte) to store the indices of an array with 2^8 elements, which is just dumb.Some of you might be thinking: you don't need to store it the same way it's written, you can just substract 1 from whatever the user typed and convert it behind the scenes.
Yes, you could subtract 1, but then you would be making the whole system more complex, opaque, and unelegant, while hiding information from the programmer for no good reason.