News for hackers. Stuff that matters.
Re:Why do arrays start at 0? by atwood22 on Wednesday August 24, 2022 @01:07PM (#32582467)
No, birthdays are 1 indexed. Your Nth birthday is the day you turn N years old. When you're 1 year old, you've been alive for 1 year, not 2 years.
Re:Why do arrays start at 0? by randomdata on Wednesday August 24, 2022 @01:08PM (#32582481)
The moment you are born you are 0 years old (or perhaps 0.75 years old, but we don't usually recognize that). We count from zero in this case, at least implicitly.

In some cultures you are considered 1 the moment you are born, so the zero indexing isn't universal here, but typical in North America as noted earlier.

Re:Why do arrays start at 0? by themacks on Wednesday August 24, 2022 @01:16PM (#32582604)
Typical counting of things starts from 0. If you count apples you implicitly start at zero and add 1 for each apple. If you count age, you start at birth (0) and count years; one for each birthday. That isn't zero based. The difference is the index of the item between the starting point and the next item. In zero based this item is number 0, in one based, this item is number 1. The first year of life is generally considered the year following birth.
Re:Why do arrays start at 0? by samatman on Wednesday August 24, 2022 @08:40PM (#32587843)
This is a philosophically deep point which took me a long time to grasp.

There is a narrowing from "nothing at all" to "zero apples" which doesn't happen 'in the world' but is a necessary precondition to counting apples. The existence of any apple is a requirement for there to be zero of them before you put anything in the basket.

Re:Why do arrays start at 0? by dylan604 on Wednesday August 24, 2022 @01:56PM (#32583217)
>If you count age, you start at birth (0) and count years; one for each birthday.

nitpick: unless you were born on Feb 29.

Re:Why do arrays start at 0? by somat on Wednesday August 24, 2022 @03:08PM (#32584256)
I just dealt with this problem(how to store periodic events(including birthdays)). It is a surprisingly difficult problem. After reading up on postgres interval types my latest attempt uses them to store events, where a per year event(like a birthday) is stored as "2 months 15 days". it turns out the postgres project has put quite a bit of thought into making interval types work as expected with regards to months, not an easy task when you consider how difficult it is to treat dates mathematically.

The nice part is that now February 29 "just works" the downside is the impedance between how months and days are numbered and a how an offset from the epoch(beginning of the year) is defined. January 3rd(1-3) is stored as "0 months 2 days" as when it hits, 0 months have passed and 2 days have passed.

So the specific case of February 29 hits when 1 month has passed and 28 days have passed. 3 years out of 4 this will be the same as "2 months 0 days"(3-1) but every forth year this will be(2-28). As an aside, and the specific reason I went with interval types, every event past feburary 29 works just fine with or without a leapyear, that is, the extra day in the middle does not mess up the offset to days after it.

Honestly I curse a little as I wish months and days were 0-based. At least clocks get this right, almost, 12 hour clocks are a special breed of stupid. start at 12, then go to 1 and proceed up to 11. 24 hour clocks properly start at 0. The worst part about 12 hour clocks is that it is almost correct, replace the 12 with a 0 and it every thing be the same but now it makes sense from a moduler math point of view.

A special curse is reserved when I think about how there is no year zero. https://www.postgresql.org/docs/13/functions-datetime.html#F...

Re:Why do arrays start at 0? by copperx on Wednesday August 24, 2022 @02:11PM (#32583482)
I didn't know that. Do you get to be 1 year old if you are born on Feb 29, to account for leap years?
Re:Why do arrays start at 0? by dylan604 on Wednesday August 24, 2022 @05:32PM (#32586055)
You're just 1/4 of the age of everyone else born the same year. You have the same number of laps around the sun as those people, but you've definitely had fewer birthdays. It's a common joke for leap year babies.
Re:Why do arrays start at 0? by goatlover on Wednesday August 24, 2022 @02:24PM (#32583667)
> If you count apples you implicitly start at zero and add 1 for each apple.

If that's the case, then how did the ancient Greeks or Romans count before zero was an acceptable concept in their counting system?

Re:Why do arrays start at 0? by unbalancedevh on Wednesday August 24, 2022 @04:34PM (#32585366)
By describing it in other ways, I imagine: "How many apples do you have?" "I don't have any."
Re:Why do arrays start at 0? by atwood22 on Wednesday August 24, 2022 @01:12PM (#32582539)
No, we don't count from 0. That's like saying we start counting a baker's cup from 0 because you can have half a cup.
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?
Re:Why do arrays start at 0? by kazinator on Wednesday August 24, 2022 @01:19PM (#32582643)
What do you do for a living, and why are they paying you not to understand this?
Re:Why do arrays start at 0? by atwood22 on Wednesday August 24, 2022 @02:28PM (#32583711)
Do you know the definition of countable? A set S is countable if there is a one-to-one mapping from S to N where N is the natural numbers. Do you know that 0 is not a member of the natural numbers? We literally start counting at 1 by definition of countable.
Re:Why do arrays start at 0? by lupire on Wednesday August 24, 2022 @03:36PM (#32584652)
Nope.

Is the empty set countable? (Yes.)

Dictionary:

nat·u·ral num·bers

  the positive integers (whole numbers) 1, 2, 3, etc., and sometimes zero as well

Countable: https://en.wikipedia.org/wiki/Countable_set

Set theory:

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

Re:Why do arrays start at 0? by atwood22 on Wednesday August 24, 2022 @04:05PM (#32585046)
From your own link on countable sets:

> Equivalently, a set S is countable if there exists an injective function f : S → N from S to N; it simply means that every element in S corresponds to a different element in N.

Defining N is usually done via a successor set, on which case 0 makes no sense to include.

Re:Why do arrays start at 0? by lupire on Wednesday August 24, 2022 @07:05PM (#32587038)
A successor set is the set of successors of... 0 or 1, depending on what you are doing.
Re:Why do arrays start at 0? by kazinator on Wednesday August 24, 2022 @05:20PM (#32585918)
An empty set is countable; it has an empty mapping to the natural numbers. Its cardinality is zero.
Re:Why do arrays start at 0? by lupire on Wednesday August 24, 2022 @07:10PM (#32587096)
And its ordinalitiy is also 0.

Standard construction of ordinals is that each ordinal is the set of all its predecessors. (0 has no predecessors , hence 0 is the empty set.) (And so finite ordinals have the same ordinaliity as cardinality).

Re:Why do arrays start at 0? by pwdisswordfish9 on Thursday August 25, 2022 @07:59AM (#32592517)
Show me a mathematical text where ‘ordinality’ is defined.
Re:Why do arrays start at 0? by samatman on Wednesday August 24, 2022 @08:42PM (#32587863)
Are you a time traveller from the late 17th century?
Re:Why do arrays start at 0? by bmacho on Wednesday August 24, 2022 @02:45PM (#32583950)
Can't they just .. disagree?

Birthdays are clearly 1 indexed, the first birthday is indexed with 1, and not with 0.

Re:Why do arrays start at 0? by ziml77 on Wednesday August 24, 2022 @03:35PM (#32584647)
They day you're born is birthday number 0
Re:Why do arrays start at 0? by bmacho on Wednesday August 24, 2022 @05:25PM (#32585985)
Exactly.

Birthday[0] gives you an out of range exception, since there is no birthday called 0th. Birthdays are [first,second,..] indexed from 1: brithday[1] = first, birthday[2] = second, and so on. That's what indexing a series from 1 means.

Re:Why do arrays start at 0? by emaginniss on Wednesday August 24, 2022 @02:28PM (#32583712)
Ok, use the baker and cup as an example. If you have an empty cup and put half of a cup of flour in it, you now have 0.5 cups of flour. Notice the zero before the ".5". That is us, normal humans, realizing that until you add enough to have 1 of something, you have between 0 and 0.999 repeating.
Re:Why do arrays start at 0? by bregma on Wednesday August 24, 2022 @02:30PM (#32583756)
When I'm baking I start by zeroing the scale, then adding enough flour to reach 500 g (or whatever the recipe calls for). That's counting from zero.
Re:Why do arrays start at 0? by randomdata on Wednesday August 24, 2022 @01:13PM (#32582545)
If we (speaking as a North American) count from 1, does that mean other cultures (e.g. Korean) count from 2?
Re:Why do arrays start at 0? by atwood22 on Wednesday August 24, 2022 @01:16PM (#32582591)
No, it just means we have a different notion of what a year is in regards to age. Similar to how different cultures can use different units of measurement for length, mass, etc.
Re:Why do arrays start at 0? by randomdata on Wednesday August 24, 2022 @01:17PM (#32582610)
Yes, exactly. One of which carries an implicit zero indexing. The date of birth doesn't disappear just because you decided to use a different measuring device.
Re:Why do arrays start at 0? by atwood22 on Wednesday August 24, 2022 @01:41PM (#32582961)
No, it doesn’t carry an implicit 0 index. Measuring age (in the West) is like measuring distance. You start at 0, but that doesn’t mean the first item is at index 0.
Re:Why do arrays start at 0? by randomdata on Wednesday August 24, 2022 @01:47PM (#32583076)
If you took a standard ruler, a measurer of distance and which has literal index marks painted on it, and placed items along it, the item found at the head of the ruler would be found at the 0th index. You're quite right that we think of birth and its anniversaries in the same way.
Re:Why do arrays start at 0? by samatman on Wednesday August 24, 2022 @08:43PM (#32587867)
Birthdays are literally indexed by the moment of birth as zero.

You can't possibly be serious.

Re:Why do arrays start at 0? by 8note on Wednesday August 24, 2022 @02:49PM (#32583998)
I start with a empty cup, then I fill it up to 1 cup.

I then put it in an initially empty bowl

Re:Why do arrays start at 0? by samatman on Wednesday August 24, 2022 @08:42PM (#32587857)
Yes this is correct!

The milliliters in a baker's cup are a scale based on 0!

Re:Why do arrays start at 0? by rcoveson on Wednesday August 24, 2022 @01:25PM (#32582722)
No, old calendar systems are one indexed. In those system, there is literally no year zero; the first year is year one. This leads to crazy things like year 100 being part of the "first century" and year 101 being part of the "second century".

That is not the case with age or birthdays which are, thankfully, zero indexed. The first year of human life is age=0, birthdays=0.

Re:Why do arrays start at 0? by samatman on Wednesday August 24, 2022 @08:45PM (#32587885)
So that we don't create more falsehoods programmers believe about dates, ISO has defined decades and centuries as starting with 0, not 1.

So as far as your job is concerned, that's when they start. Hope that helps.

Re:Why do arrays start at 0? by lupire on Wednesday August 24, 2022 @03:40PM (#32584697)
It's not "crazy". No one care about which century X00 is. The term "century" doesn't have enough sig figs. X00 is "the turn of the century".
Re:Why do arrays start at 0? by rcoveson on Wednesday August 24, 2022 @04:24PM (#32585274)
If you don't care then sure, it's not crazy, but if you did care then believe me, it is crazy. Crazy enough that astronomers[0] and software engineers[1] rebelled against the historian's practice and renamed the years preceding 1 AD in the proleptic gregorian calendar year 0, year -1, year -2, et cetera. A major benefit of this is it allows the leap year pattern to stay consistent and the rule to remain legibile for all years, going back before 1 AD. It's also nice because it lets us say "the 90's were the last ten years of the 20th century" and be correct.

0. https://en.wikipedia.org/wiki/Astronomical_year_numbering

1. https://docs.oracle.com/javase/8/docs/api/java/time/temporal...

Re:Why do arrays start at 0? by csours on Wednesday August 24, 2022 @01:12PM (#32582534)
Your birth day is the day you are born.

Your first birthday is the first anniversary of your birth day.

We celebrate the anniversaries of our birth day.

Re:Why do arrays start at 0? by treis on Wednesday August 24, 2022 @02:06PM (#32583398)
Yep, clearer in Spanish. They say cumpleaños which literally means completed year.
Re:Why do arrays start at 0? by wruza on Wednesday August 24, 2022 @06:33PM (#32586691)
Haha, this thing is messed up. Your "first birthday" is technically second, because the first was at your, well, day of birth. But we people love to complicate things and count 1st birthday as a number of annual celebration events after the first mm-dd of birth. Off by one as it is.
Re:Why do arrays start at 0? by brianzelip on Wednesday August 24, 2022 @01:10PM (#32582503)
So how old is a not-yet-1-year old?
Re:Why do arrays start at 0? by nomel on Wednesday August 24, 2022 @01:18PM (#32582632)
Elapsed time timers start at 0. Time is continuous. The elapsed time being “out of the womb”, that we call “age”, starts near 0. Five minutes after birth, the baby has been in the world for, or it’s age is, five minutes. If someone asked how old a new baby is you could hear “3 weeks”.

Another definition might be from conception. But birth being “one year old” is illogical. The sperm didn’t even exist yet, one year before birth.

Re:Why do arrays start at 0? by xxs on Wednesday August 24, 2022 @02:21PM (#32583639)
Your mistake is using years - use milliseconds (or nanoseconds) when you wish to express a duration. Years don't even have the same duration/length (leap years, and leap seconds)
Re:Why do arrays start at 0? by atwood22 on Wednesday August 24, 2022 @01:11PM (#32582521)
N days or N months depending on how old the baby is.
Re:Why do arrays start at 0? by rcoveson on Wednesday August 24, 2022 @01:30PM (#32582792)
And before an hour has even passed, we'd probably say "minutes old" or perhaps "not even an hour/day old", all to avoid saying "zero days/months/years old". But some might still say zero days old, and they'd be both understood and correct (at least logically if not stylistically). That's the "implicit zero" everybody is talking about. We avoid saying it, but that's just a convention of communcation. Logically it's there. You're zero days old before you're one day old.
Re:Why do arrays start at 0? by randomdata on Wednesday August 24, 2022 @01:15PM (#32582587)
And it turns out that 0 days, 0 months is 0 years.