r/ProgrammerHumor • • Sep 18 '26

Meme almostDroppedTheCourse

Post image
581 Upvotes

79 comments sorted by

View all comments

58

u/himai1 Sep 18 '26

Me when something I am learning doesn't behave exactly like how I expect and identically to the things I already know

19

u/Valuable_Leopard_799 Sep 18 '26

Yeah, people should stop being weird about indexing.

Or I'll pass you a vector with a range of [Red..2.5].

5

u/willow-kitty Sep 19 '26

How would that work? How many indices would even be in that range? Would it be looking at a map and referencing the keys that would sort between those values?

2

u/Valuable_Leopard_799 Sep 19 '26 edited Sep 19 '26

I was half joking by combining these but some languages allow you to use any discrete Enumerable type as your bounds.

So a single precision fixed width number would be totally valid with for example indices 0.0, 0.1, 0.2, ..., 2.4, 2.5. It would just make an array of length 26.

Or obv. [1.0..2.5] to start at one or [42..64] to have an array with valid indices only integers between 41 and 65.

You can obviously also use Enums, so you declare an array of RGB colours and get indices Red, Green, Blue, and then you can both index arr[Red] and also slice into it arr[Green..Blue] (slice of length 2). These are a separate type arr[0] would not be valid and wouldn't typecheck.

Btw sorting between sounds amazingly weird.

6

u/ChillyFireball Sep 19 '26

I look at it this way: Some games map the attack button to right trigger. Other games map the attack button to X. Both of those can work. But if you map the attack button to the D-pad, I'm gonna question your sanity.

2

u/LoyalSol Sep 19 '26 edited Sep 19 '26

Yeah the 1-indexing thing is funny for mememing, but if anyone is serious about that it literally makes zero difference in actual applications.

I have done both pretty extensively and it's literally no difference in the long run.

1

u/LoyalSol Sep 19 '26

Yeah the 1-indexing thing is funny for mememing, but if anyone is serious about that it literally makes zero difference in actual applications.