logoalt Hacker News

9rxlast Tuesday at 5:48 PM1 replyview on HN

> and you have absolutely no idea if the string was "0" or "not zero"

You do – err will tell you. But in practice, how often do you really care?

As Go prescribes "Make the zero value useful" your code will be written in such a way that "0" is what you'll end up using downstream anyway, so most of the time it makes no difference. When it does, err is there to use.

That might not make sense in other languages, but you must remember that they are other languages that see the world differently. Languages are about more than syntax – they encompass a whole way of thinking about programs.


Replies

kbolinolast Tuesday at 6:05 PM

I think it's worth noting that, while the general consensus has converged around (T, error) meaning T XOR error, it does not necessarily mean that. There are some places that violate this assumption, like the io.Reader and io.Writer interfaces. Especially io.Reader, where you can have (n>0, io.EOF), which also isn't even a proper error condition! (This isn't a big problem, though, since you rarely need to directly call Read or Write).

show 1 reply