I don't like defer
Ok that’s a bit of an exaggeration. It’s not that I don’t like defer, I think I might just prefer something else. But I’m not sure why. In this blog post we’ll take a look defer and its alternatives, and hopefully I’ll come out with a better idea of my own preferences. what is defer? Okay, the necessary part. What am I even talking about? defer is a statement in Go that defers some function call to the end of the current function. The reason I believe defer exists is for resource cleanup. Often in programming you’ll have some kind of value for which there’s some necessary cleanup logic. An example of this might be a file which you have to eventually close, or a mutex you’ll have to eventually unlock or a connection you’ll have to eventually disconnect from. ...



