News for hackers. Stuff that matters.
Re:Go 2, here we come by growse on Thursday November 29, 2018 @07:12PM (#18565433)
Shouldn't idiomatic go return an error instead? Magic number ranges for errors always seemed a bit old-fashioned.
Re:Go 2, here we come by pxia on Thursday November 29, 2018 @07:23PM (#18565510)
It's just an example... Another example would be you want to iterate your array in reverse. The normal `for (uint i=size-1; i >= 0; i--)` won't work.
Re:Go 2, here we come by growse on Friday November 30, 2018 @06:34AM (#18568350)
That example doesn't work precisely because you're conflating the concept of the loop counter (which type represents an integer that needs to be able to go <0) with the array index accessor. There's no reason for these two things to be the same type, it's just a pattern that accidentally works because we allow arrays to be accessed using a type that represents negative numbers.

What would be a more compelling argument is to use int in the same way that python does - a negative accessor means offset from the end of the array, not the start. I'm not sure golang lets you do this though...?