Go is a great language, but lately it has been bothering me that my codebase is now filled with some, for lack of a better word, stupid nil and err checks.
Here is a stupid pattern I have written too many times. I open a file, pass the pointer through three functions, and then somewhere deep in the third one, I add: if err != nil. What exactly is that protecting me from?
If the file handle was ever going to be nil, the failure should have happened at os Open, not three function calls later.
The same thing happens with error propagation.
os Open fails. I wrap the error. The caller wraps it again. Then another layer wraps it one more time. Eventually, I am dealing with an error that looks like this:
failed to process: failed to read: failed to open: no such file or directory
Now, I still have to read the whole chain to discover that a file was missing. ahhhhhh. Yes, I do prefer having explicit errors over handling exceptions. But sometimes this feels like a little too much.
Yes, Go does make my codebase super defensive. But none of this makes Java a better language :)
I just spent part of my day deleting a bunch of nil checks, and hence the rant.
End of rant. Sorry, but not sorry.