logoalt Hacker News

Dr_Emann • yesterday at 7:09 PM • 2 replies • view on HN

In only one of those examples do you get a T that's invalid.


Replies

segfaltnh • yesterday at 7:48 PM

True, Go does require you to follow a convention here (dont use T if err is not nil). In practice it works pretty well, though obviously not bullet proof.

I believe some exceptional languages are similar, like Ruby. If you rescue but dont abort, the variable on the left hand side gets a nil when that may otherwise not be possible. Of course, that is handled cleanly as its own error.

vips7L • yesterday at 7:48 PM

I don't see how. Unless it's the Go example where you get (nil, err)?