Live data from Hacker News

Why do arrays start at 0?

buttondown.email

101–110 of 702 posts

Re: Why do arrays start at 0?

#102
I can understand the rationale for 0 and 1. I can even understand the rationale for a arbitrary range (from -5 to +10) in current era where languages have iterated for many generations.

However I did not understand why they would have a range in the early days of programming. On one hand it would have been hard to make a language and its compilers and then you add arbitrary ranges?

Re: Why do arrays start at 0?

#103

I've discussed this a lot in real world in a different field: apartment floors. In Japan (where I live) they are 1-indexed, where the floor on the ground is number 1, while in Spain (where I am from) they are 0-indexed, where the floor on the ground is number 0. Both have inconsistencies, like in Spain you might have a "middle ground" (entresuelo) which is neither 0 nor 1, but sits between, and is normally commercial…

It seems like most newer buildings in the US and EU have "G" or "L" be the ground floor (0 / PB), and then the floor above is "1".

In older buildings, the ground floor is usually "1" - which means the floor above has to be "2".

Re: Why do arrays start at 0?

#104
post #36

Earlier quoted context omitted.

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.

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.

Yep, clearer in Spanish. They say cumpleaños which literally means completed year.

Re: Why do arrays start at 0?

#105
post #87

Earlier quoted context omitted.

> when we count, we start at 1, we talk about the "1st" Although often with an implicit zero. Under typical North American culture, your 1st birthday, for example, is more accurately the first anniversary of your birthday. Your birth is zero indexed.

Birthdays are anniversaries. Anniversaries are annual activities when we celebrate/honor past events. They do not include the event itself. The first anniversary is 1 year after the initial event.

> Birthdays are anniversaries.

Indeed they are, which is why I literally said so in the previous comment. Did you forget to finish reading it?

> They do not include the event itself.

That is true because the event itself is implied information. There is no value in speaking of it. If you stand before us, we can be certain that you had a day of birth (your 0th anniversary). We don't necessarily know how many times you've gone around the sun following that, however, so that is where we find value in communicating additional information.

If you were counting apples, there is the state where you have no apples (index 0), the state where you have one apple (index 1), the state where you have two apples (index 2), etc. When counting you don't need to worry about index 0 because the no apple state is naturally implied. It only becomes interesting and worthy of communication when you have at least one apple to speak of, thus you start at 1. The state found at index 0 is still implicitly there, though.

Re: Why do arrays start at 0?

#106

It really comes down to a choice between a machine-focused (0) or human-focused (1) approach. The 0 makes a lot of sense in a C pointer world where memcpy and other alike functions can be written very thight. The 1 makes a lot of sense in a human world, when we count, we start at 1, we talk about the "1st", counting on finger starts with 1, etc. I once were at a Lua (1 indexed language) conference where this was disc…

Human makes a lot of inconsistent thing: We usually think the 1st floor, and the basement as 1st underground floor ( -1), but the floor jumps from 1 to -1!

Also, the time jump from 11AM to 12PM to 1PM! So I think more human friendly sometimes means more confusing.

Re: Why do arrays start at 0?

#109
I've spent so long working with both 0-indexed and 1-indexed (I work with Lua a LOT at work) that it makes almost no difference to me, and I can switch between the two with usually no hiccups.

Either one is something you get used to with practice. I do prefer 0-based, but 1-based isn't as big of a deal as many people treat it in the vast majority of situations, and almost every situation where you'd be using something like Lua in the first place.

Re: Why do arrays start at 0?

#110
post #3

Pascal's arrays start at 1, at least by default.

Pretty much all variants of BASIC have arrays starting at 1.

Pascal is a variant of ALGOL-60, made in part because Wirth thought ALGOL-68 was way too complicated. BASIC instead comes from the FORTRAN line.
Post reply on HN