Re:Good-bye core types; Hello Go as we know and love it
by 9rx on Friday March 28, 2025 @07:14AM
(#43503975)
You’d return -1. A successful read won’t read negative bytes. The non-error value remains useful.
[ Parent
| on HN ]
Re:Good-bye core types; Hello Go as we know and love it
by int_19h on Friday March 28, 2025 @09:55PM
(#43512046)
That's actually a great example. Note that it is a distinct sentinel error value that needs to be checked for (contrary to your initial assertion), and if you forget to do it, you'll just end up with garbage.
But also, let's say the read function in question is named ReadInt32. Then what does it return on error?