3 ms·
This is good advice. I had a hard time with this aspect of go until wrapping clicked. I think (as mentioned in the post) creating custom errors can be extremely
by steve_adams_86 2y ago
This is good advice. I had a hard time with this aspect of go until wrapping clicked. I think (as mentioned in the post) creating custom errors can be extremely useful as well, in moderation. Go error handling is really not that bad if you embrace it and use it well.
Like many things in go, I think a lot of us unwittingly hope it will behave in familiar ways because so much of the language seems simple or intuitive. Unfortunately, without a good grasp on it, many parts of go will appear to cooperate with your hopes until it doesn’t.
I think a great example of this is the type system. There is a correct way to use it, but it’ll let you misuse it quite extensively before things start to implode. Errors are a bit like this. You can return raw errors for a long time and it’ll seem fine until suddenly, debugging and tracing issues is incredibly inconvenient and unintuitive.
I found the book “Learning Go” really helpful in breaking these bad habits and helping me get acquainted with how things actually work under the hood.
- mst 2y agoThe Jon Bodner one? There seems to be a few.
- steve_adams_86 2y agoOh, whoops. That’s the right one. I should have specified! I found it a perfect level to get a competent programmer familiar with Go without oversimplifying or omitting too much. I came away from it significantly more productive and confident with the language.