Why Go error handling is my favorite
Go has very simple and efficient error handling mechanism. Error as value is very powerful concept and some people find it annoying. I think errors should be annoying so that we don’t ignore them. Most notable aspects of go’s error handling I found myself are: It is just straight forward and simple, I didn’t have to do anything clever to tweak it and make it more erganomic. I got used to it quickly after a bit of skepticism. I believe It’s common for us to force a familiar paradigm when we try new languages and when it’s different, we tend to question it. I had to think more about error handling and it made me write more robust code. I always write prototypes in other languges by ignoring errors and it can slip to production, even if I ignore errors in go, there is an explicit _ which reminds me that I’m ignoring an error. Error as value In go, a typical function defintion can give away if it returns an error or not. If a function returns an error, it’s usually the last return value. This makes it very easy to identify if a function can return an error or not. ...