News for hackers. Stuff that matters.
Re:Microfeatures I'd like to see in more languages by caseyohara on Thursday January 05, 2023 @06:06PM (#34268275)
Ruby happily allows this and I can't recall it ever being an issue. It's no more prone to errors than `x` being greater than the number of elements.

> arr = ["a", "b", "c", "d", "e"]

> x = -2

> arr[x]

=> "d"

Re:Microfeatures I'd like to see in more languages by edflsafoiewq on Thursday January 05, 2023 @08:53PM (#34269931)
If you intended to calculate an index and you accidentally get len(arr), you get a runtime error. But if you accidentally get -1 you silently get the last element instead. Similar to the argument about signed/unsigned indices in low level languages.
Re:Microfeatures I'd like to see in more languages by ilyt on Thursday January 05, 2023 @09:29PM (#34270197)
If you calculated wrong you can land on positive-but-existing value just fine...

> Similar to the argument about signed/unsigned indices in low level languages.

Think that one has to do more with convenience where most of stuff uses int by default