this post was submitted on 11 Feb 2025
640 points (96.9% liked)

Programmer Humor

20039 readers
2062 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 2 points 5 hours ago (1 children)

Yeah, but if we went back and time and changed it then there wouldn't be other stuff relying on it being 0-based.

[–] [email protected] 2 points 4 hours ago (1 children)

It was not randomly decided. Even before arrays as a language concept existed, you would just store objects in continuous memory.

To access you would do $addr+0, $addr+1 etc. The index had to be zero-based or you would simply waste the first address.

Then in languages like C that just got a little bit of syntactic sugar where the '[]' operator is a shorthand for that offset. An array is still just a memory address (i.e. a pointer).

[–] [email protected] 1 points 2 hours ago

I know. But in the alternate reality where we'd been using 1-based indices forever you'd be telling me how useful it is that the first element is "1" instead of zero and I'd be saying there are some benefits to using zero based index because it's more like an offset than an index.