2 ms·
Someone would sure enjoy golang!
by drivebyacct2 14y ago
Someone would sure enjoy golang!
- wonderzombie 14y agoMore specifically, the `defer` keyword lets you handle cleanup in the case of failure a bit more neatly. The gotos can be replaced with stuff like this: foo, err := bar() if err != nil { return err } defer foo.cleanup() // or what have you Now, right before the function returns, Go will call `foo.cleanup()` and your `cleanup()` call sits right next to the initialization code. It's a lot easier to tell whether or not you are (or someone else is) doing cleanup properly.