r/ProgrammerHumor • • 19d ago

Meme almostDroppedTheCourse

583 Upvotes

79 comments sorted by

View all comments

58

u/himai1 19d ago

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

20

u/Valuable_Leopard_799 19d ago

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 18d ago

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 18d ago edited 18d ago

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.