Defer to Clean Up
Use defer to clean up resources such as files and locks.
Bad | Good |
---|---|
|
|
Defer has an extremely small overhead and should be avoided only if you canprove that your function execution time is in the order of nanoseconds. Thereadability win of using defers is worth the miniscule cost of using them. Thisis especially true for larger methods that have more than simple memoryaccesses, where the other computations are more significant than the defer
.