News for hackers. Stuff that matters.
Re:Why do arrays start at 0? by kazinator on Wednesday August 24, 2022 @01:23PM (#32582697)
The counting activity doesn't begin when the first item is registered; it begins when the counter is initialized to zero. A decision is made to begin counting, along with the realization that nothing has been counting yet. That's when counting has started. When the first item is seen, the counting is then continuing.

Suppose your job is to count some events. You check in for work at 8:00 a.m., but the first event has not registered until noon. By your logic you should not be paid for four hours, because you're paid to count, and counting started at 1.

Re:Why do arrays start at 0? by lupire on Wednesday August 24, 2022 @03:29PM (#32584562)
Are you sure?

We are talking about the he numbering, not the work-doing.

You start waiting at 8, and you wait between events. But you only count (increment) when an event happens.

The 0 comes for free when you are ready to count (hello golang and C++, as well as human intuition).

When you count stars in the sky you don't say "0, 1, 2".

You say "..., 1, 2", or if no stars show up, you say "there are 0" after timer expires.

Re:Why do arrays start at 0? by kazinator on Wednesday August 24, 2022 @05:22PM (#32585947)
> But you only count (increment) when an event happens.

Increment what?

> When you count stars in the sky you don't say "0, 1, 2".

No, you say, "I'm going to start counting stars now. Okay, 1, 2, ...".

The preparation part is the zero. You counted stars before and reached some number; you're not starting at that number.

Re:Why do arrays start at 0? by anigbrowl on Wednesday August 24, 2022 @04:45PM (#32585499)
You're still thinking like a computer. Most people think of counting in terms of 'here are some apples, how many exactly?'

If you just look at an empty space, the # of apples is equivalent is equivalent to the # of dinosaurs, but they're only equivalent by their absence.

Re:Why do arrays start at 0? by atwood22 on Wednesday August 24, 2022 @02:29PM (#32583738)
No, the mathematical definition of counting (i.e. whether or not a set is countable) involves mapping to the natural numbers, which doesn’t include 0.
Re:Why do arrays start at 0? by kazinator on Wednesday August 24, 2022 @05:27PM (#32586008)
I don't think your definition is complete. We can count a set by mapping its elements to the natural numbers, and then identifying that number which is highest. However, we must have a provision for identifying zero as the highest when the set and mapping are empty.
Re:Why do arrays start at 0? by 8note on Wednesday August 24, 2022 @02:47PM (#32583983)
Math counting doesn't care where you start. You could start -400 if it's useful for the problem
Re:Why do arrays start at 0? by lupire on Wednesday August 24, 2022 @03:32PM (#32584597)
You can name things however you want, but there is a canonical bijection to zero-based ordinals.

https://en.m.wikipedia.org/wiki/Ordinal_number

Re:Why do arrays start at 0? by goatlover on Wednesday August 24, 2022 @02:30PM (#32583745)
What counter? You're saying a counter exists before people start counting? Is this a form of mathematical Platonism?
Re:Why do arrays start at 0? by kazinator on Wednesday August 24, 2022 @05:18PM (#32585903)
A counter can be lazily instantiated just before the first item is counted.
Re:Why do arrays start at 0? by lupire on Wednesday August 24, 2022 @03:38PM (#32584684)
What does your stopwatch say right now?

Your pedometer?

Your traffic clicker?

Re:Why do arrays start at 0? by goatlover on Wednesday August 24, 2022 @11:31PM (#32589148)
Those are devices, not the spoken language.
Re:Why do arrays start at 0? by kazinator on Thursday August 25, 2022 @05:28PM (#32600174)
So if the counter doesn't speak, there is no counting?