this post was submitted on 01 Nov 2024
491 points (97.7% liked)

Programmer Humor

19655 readers
945 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 1 year ago
MODERATORS
491
Programmers Contest (infosec.pub)
submitted 3 weeks ago* (last edited 3 weeks ago) by [email protected] to c/programmer_humor
 

Shamelessly stolen from Reddit. No source in the original post.

all 16 comments
sorted by: hot top controversial new old
[–] [email protected] 31 points 3 weeks ago* (last edited 3 weeks ago) (6 children)

I've heard a lot of arguments in favour of starting at 1 and as a "start at 0" person, I'm starting to question my beliefs and am as confused as I was at 3 am when I saw my cat piss from inside her litter box onto the parquet flooring and then slip on it.

[–] [email protected] 44 points 3 weeks ago (2 children)

Not indexing at zero seems like a waste of a perfectly good integer.

[–] [email protected] 20 points 3 weeks ago (1 children)

Yea ther is a big difference between indexing and counting

[–] [email protected] 6 points 2 weeks ago

Element 0 is the first element of the list

[–] [email protected] 8 points 2 weeks ago

Unless you are saving it for something else, like the header of a table:-).

[–] gnutrino 15 points 2 weeks ago

True programming chads don't index at all, they just bind functions to the list monad.

[–] [email protected] 14 points 3 weeks ago

Indexing by zero has a huge positive impact on the correctness of complex operations like joining intervals, that nobody trusts themselves to write anyway and always pack behind a well-verified library.

But I think the reason we have it is because C maps it almost immediately into memory offsets.

[–] [email protected] 8 points 3 weeks ago

Like any other convention, it's not really a big deal either way. Fortran gets along just fine with 1-indexing.

[–] [email protected] 3 points 2 weeks ago

Find yourself a language that allows negative indices to count back from the end of an array.

In those languages, index 0 is usually the first element, but if you're particularly perverse and negate your indexing, you can start at 1, or rather -1, at the other end and work backwards.

0-indexing originally comes from needing to add to the array's base memory address to locate elements. If you have an array at memory address 1234, you might expect to find the first element at that address, which would be 1234+0, and the next at 1234+1, etc.

1-indexing started as either a deliberate abstraction from that idea, and/or else there's something else stored at 1234 that the array data type needs and the real elements start at 1234+1.

All that said, there's at least one language that insists the indices of an array be of a subtype of some Integer type that must have a limited range. Then you can start and end wherever you like, and the whole 1 vs 0 business is meaningless (except to whoever writes the compilers for that language anyway).

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

Find yourself a language that allows negative indices to count back from the end of an array.

In those languages, index 0 is usually the first element, but if you're particularly perverse and negate your indexing, you can start at 1, or rather -1, at the other end and work backwards.

0-indexing originally comes from needing to add to the array's base memory address to locate elements. If you have an array at memory address 1234, you might expect to find the first element at that address, which would be 1234+0, and the next at 1234+1, etc.

1-indexing started as either a deliberate abstraction from that idea, and/or else there's something else stored at 1234 that the array data type needs and the real elements start at 1234+1.

All that said, there's at least one language that insists the indices of an array be of a subtype of some Integer type that must have a limited range. Then you can start and end wherever you like, and the whole 1 vs 0 business is meaningless (except to whoever writes the compilers for that language anyway).

[–] [email protected] 7 points 3 weeks ago
[–] [email protected] 3 points 2 weeks ago

Look, I like 1 indices languages like R and Lua.

[–] [email protected] 3 points 3 weeks ago

Pascal programmers are confused.

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

Millions of Lua devs must despair

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

Retired racing driver Damon Hill approves this post.