Hacker News new | ask | show | jobs
by quelsolaar 531 days ago
Not right there, some other place in the function. Also people will start adding defer in macros and then things will go sideways.
1 comments

> Not right there, some other place in the function.

Exactly. Both C++ RAII (constructors/destructors) and C23 defer are awful. They make the behavior implicit; in effect they tie an indefinitely large (and growing) baggage to scope termination without the source code reflecting that baggage.

Cascading gotos (or the arrow pattern) are much better. Cleanup code execution is clearly reflected by location in the source code; the exit path can be easily stepped through in a debugger.