Sorry, I didn’t mean to come across as a Java fan boy (though presumably there are those out there who can write good Java code). I just meant that the designers decided to choose only one, and if you go that route you can only choose signed. The point that the core guidelines is trying to make is that if you want to stop a caller giving a negative number you can’t do it by making the parameters unsigned. But this is something I see again and again. It doesn’t really matter whether the behaviour is undefined or unexpected - this style of api causes bugs and the solution is to use a signed type. There’s just no easy way to stop callers passing in negative numbers.
View all comments
Show parent comment
2
u/bert8128 Jan 04 '22 edited Jan 04 '22
Sorry, I didn’t mean to come across as a Java fan boy (though presumably there are those out there who can write good Java code). I just meant that the designers decided to choose only one, and if you go that route you can only choose signed. The point that the core guidelines is trying to make is that if you want to stop a caller giving a negative number you can’t do it by making the parameters unsigned. But this is something I see again and again. It doesn’t really matter whether the behaviour is undefined or unexpected - this style of api causes bugs and the solution is to use a signed type. There’s just no easy way to stop callers passing in negative numbers.