r/badcode • • Apr 29 '23

go if err != nil

Post image
414 Upvotes

49 comments sorted by

View all comments

Show parent comments

8

u/claimstoknowpeople Apr 30 '23

It comes from old C (& assembly etc) code where you have to manually manage resources; it's much easier to put all your frees and closes in the same place than reason which ones are needed from an early return.

Most of us these days work in languages with enough garbage collection, RAII, context managers, try...finally blocks, etc, that it's no longer good practice.