News for hackers. Stuff that matters.
Re:The Big TDD Misunderstanding by jerf on Monday March 21, 2022 @09:35AM (#30753922)
abs on machine-sized integers has another easy-to-make mistake: what's the absolute value of the signed byte -128?

You face some hard decisions on that one. None of the error handling paradigms are good at handling the class of numeric errors that people really, really want to pretend don't exist because no matter what kind of error they throw they're a major pain to deal with correctly.

Re:The Big TDD Misunderstanding by yakubin on Monday March 21, 2022 @10:00AM (#30754198)
I'd agree, if the result type was the same as the input type. However, notice that the function I wrote returns an unsigned type, so in the case of byte-sized types it would be fn abs(x: i8) -> u8, i.e. there is enough space for 128. Otherwise, good point.