Hacker News new | ask | show | jobs
by tcoff91 476 days ago
No, zero based indexing just is based on how arrays actually work. It has nothing to do with resources being scarce. You have an address for the beginning of the array and an offset. The first element has no offset so you use zero. Therefore you naturally end up with zero indexing.
1 comments

Yeah but why wasn't that converted to human 1 based indexing at the machine code level or assembly in early machines?

Maybe because they didn't want to "hide the bicycle gears"?

No, it's because it doesn't make any sense to do that. It would add a ton of complexity for no benefit.
It does make some sense: if I have some apples, and I ask a child to count them, they'll address each one starting with the number 1, not the number 0.
Indexing/addressing is not counting though. Look at a ruler. It doesn't start at 1.
Thanks that made it click.

While I understand the CS concepts, I have never really thought about the developer UX before.

Yes, indeed. But when indexing to an element in an array you aren't measuring from a zero (well, in memory you are, but not conceptually). You're conceptually pointing at an apple.
> But when indexing to an element in an array you aren't measuring from a zero (well, in memory you are, but not conceptually).

Yes you are!! In memory, and conceptually. You're conceptually moving your finger 0 spaces from the start of the apple array.