News for hackers. Stuff that matters.
Re:Why do arrays start at 0? by anigbrowl on Wednesday August 24, 2022 @04:20PM (#32585226)
Are you sure it doesn't just look that way because you are used to monospaced fonts? Ask a kid to show you their zeroth finger.
Re:Why do arrays start at 0? by TOGoS on Wednesday August 24, 2022 @05:08PM (#32585783)
As a kid, I saw these things often on multiple-choice test sheets. The tens digit at the end of each row not matching that at the beginning always seemed awkward, and I wondered why they didn't just start at zero. This was long before I did any programming.

The 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.

Re:Why do arrays start at 0? by adolph on Wednesday August 24, 2022 @05:43PM (#32586167)
Well, given that year numbering system's start in Europe, zero wasn't as broadly accepted as other digits at the time.

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

Re:Why do arrays start at 0? by marak830 on Wednesday August 24, 2022 @04:48PM (#32585546)
I asked my son to show me zero fingers(after show me 2 fingers and 5 fingers), he closed his fists.
Re:Why do arrays start at 0? by anigbrowl on Wednesday August 24, 2022 @04:53PM (#32585596)
My point exactly - there isn't an identifiable zeroth finger.
Re:Why do arrays start at 0? by colonwqbang on Wednesday August 24, 2022 @06:03PM (#32586370)
There's not a second finger either. You can convey "two" by showing any two fingers.
Re:Why do arrays start at 0? by gitonthescene on Wednesday August 24, 2022 @04:57PM (#32585646)
And? My solution? Let the kid grow up and learn.
[dead]
Re:Why do arrays start at 0? by pygy_ on Wednesday August 24, 2022 @06:09PM (#32586450)
Anecdotally, I taught my children numbers starting from zero with a similar routine, based on cardinality. They immediately got it.

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.

Re:Why do arrays start at 0? by lokedhs on Thursday August 25, 2022 @02:01AM (#32590106)
The index is the distance away from the first element. So index 0 is the first element. Index 3 is 3 away from the first element, so the fourth element.

It's the difference between ordinal and cardinal numbers. In other words, counting and indexing.

Re:Why do arrays start at 0? by pygy_ on Thursday August 25, 2022 @03:27AM (#32590693)
Well well well...

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 ...

Re:Why do arrays start at 0? by anigbrowl on Wednesday August 24, 2022 @08:23PM (#32587732)
Teaching kids about zero I have no issue with.

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.

Re:Why do arrays start at 0? by Koshkin on Wednesday August 24, 2022 @07:59PM (#32587535)
Of course there is - I can write “0” on it!
Re:Why do arrays start at 0? by karamanolev on Wednesday August 24, 2022 @07:20PM (#32587192)
Counting fingers (or other items) isn't a positional numeral system, so it's really apples to oranges. Also, "first" has a meaning of "nothing precedes it", which is separate from the indexing system", it shouldn't mean "at index 1", unless otherwise specified.
Re:Why do arrays start at 0? by polyamid23 on Thursday August 25, 2022 @07:25AM (#32592232)
Though the idea of an index as a position instead of an address is weird to me, you can indeed make that analogy. The "first" element of an array has the index zero, as in "zero elements precede it".
Re:Why do arrays start at 0? by IshKebab on Thursday August 25, 2022 @04:15AM (#32591010)
> Ask a kid to show you their zeroth finger.

They will get confused because every day counting got it wrong. In a perfect world we would count fingers from 0.