News for hackers. Stuff that matters.
Re:Why do arrays start at 0? by mananaysiempre on Wednesday August 24, 2022 @02:39PM (#32583879)
A rare case where 1-based indexing is more convenient is complete binary trees laid out breadth-first (as in a standard binary heap): parent is i div 2 and children are 2i and 2i+1 when starting at one and who knows what when starting at zero. But that’s the only one I know.
Re:Why do arrays start at 0? by wizofaus on Wednesday August 24, 2022 @04:38PM (#32585426)
Except 1-based indexing is what we use in normal language. We don't use "zeroeth" or "player (number) zero" etc. And the word "first" is shortened to 1st etc. Personally I think we'd be better off if programming languages stuck to the same convention - off-by-1 errors aren't the hardest problems to deal with but they're still annoying.
Re:Why do arrays start at 0? by ChickeNES on Wednesday August 24, 2022 @05:48PM (#32586224)
Re:Why do arrays start at 0? by wizofaus on Wednesday August 24, 2022 @09:36PM (#32588301)
Sure, it's technically a word, but hardly one you'd casually drop into your conversations (with non-programmers)
Re:Why do arrays start at 0? by Quekid5 on Wednesday August 24, 2022 @07:22PM (#32587208)
> "player (number) zero"

That would be because any game worth playing has at least one player... and so it's natural to continue from there. (In terms of language.)

Re:Why do arrays start at 0? by OscarCunningham on Thursday August 25, 2022 @05:28AM (#32591467)
You might have heard of Conway's Game of Life.
Re:Why do arrays start at 0? by Quekid5 on Friday August 26, 2022 @02:08PM (#32610819)
Fair :)
Re:Why do arrays start at 0? by lokedhs on Thursday August 25, 2022 @01:02AM (#32589713)
That's confusing ordinal and cardinal numbers. The element with index 0 is the first number. The element with index 1 is the second number, and so on.

Using the term "zeroth" is basically some form of showing off (even though it's kinda fun), but will be utterly confusing when you get to the fifty-second element which is the last in a group of 53 elements.

Re:Why do arrays start at 0? by wizofaus on Thursday August 25, 2022 @05:05AM (#32591324)
I'm not confusing them, my point about abbreviating "first" as 1st was that in typical speech we start counting at 1. Nobody says "let's start with item zero on the list". But programmers are stuck with having to say/think "item 0 in the array".
Re:Why do arrays start at 0? by lokedhs on Thursday August 25, 2022 @05:55AM (#32591605)
I don't disagree with you. I just don't think a programmer should be confused about the statement "item 0 is the 1'st item".
Re:Why do arrays start at 0? by misttar on Wednesday August 24, 2022 @05:26PM (#32585998)
The 2 major blunders in programming: 1) Off by one errors.
Re:Why do arrays start at 0? by btilly on Wednesday August 24, 2022 @03:34PM (#32584628)
With 0-based indexing the children are at 2i+1 and 2i+2. The parent is at (i-1) div 2.

Not hard to figure out.

Re:Why do arrays start at 0? by JadeNB on Wednesday August 24, 2022 @04:09PM (#32585092)
> With 0-based indexing the children are at 2i+1 and 2i+2. The parent is at (i-1) div 2.

> Not hard to figure out.

While that's true, "you just shift by 1" is equally good at all arguments for or against 0-based indexing, so deploying it here probably won't convince.

Re:Why do arrays start at 0? by btilly on Wednesday August 24, 2022 @04:43PM (#32585465)
I was not trying to convince.

That said, the effort of one versus the other is so trivial that there is no point in ever using effort as an argument either way. Doubly so because what seems like effort to us is simple unfamiliarity.

What is important is which one leads to more careless errors in practice. As a trivial example, consistent indentation takes effort, but failing to do it leads to more careless errors. Therefore everyone indents code.

The only data point I've seen on that is the side remark about Mesa in https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/E.... That remark, therefore, is the only argument that I care about.

Re:Why do arrays start at 0? by naet on Thursday August 25, 2022 @12:04AM (#32589356)
An incredibly unrare case happens all the time in my work: array[length - 1], or variations of this. Anything involving the last element of the array, and often iterating through the whole array will use something similar at some point.