Dmitrii Aleksandrov

Go Didn't Get Error Handling Right

Posted on Last edited 2 mins

Error Handling Tech

I’ve finally found a way to put this concisely:

No, Go didn’t get this right. Returning a tuple (a T and an error) isn’t an appropriate tool when you want your function to return either a T or an error. It’s a brittle hack that requires everyone to use a third-party linter on top. Otherwise, that tuple is handled incorrectly too frequently.

All of that, because Go keeps ignoring a basic feature from the 1970s that allows to you express the “or” relationships (and nullability).

APIs that are easy to use incorrectly are bad APIs.

Appendix

To be clear:


Other people’s posts:

See also my other posts about error handling .

Discuss

Comments