Why do arrays start at 0?
101–110 of 702 posts
Re: Why do arrays start at 0?
#102However 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?
#103I'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…
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?
#104Earlier 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.
Re: Why do arrays start at 0?
#105Earlier 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.
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?
#106It 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…
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?
#107Re: Why do arrays start at 0?
#108Re: Why do arrays start at 0?
#109Either 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.