News for hackers. Stuff that matters.
Re:C: Simple Defer, Ready to Use by quelsolaar on Monday January 06, 2025 @05:15PM (#42616614)
Not right there, some other place in the function. Also people will start adding defer in macros and then things will go sideways.
Re:C: Simple Defer, Ready to Use by jefbyokyie on Monday January 06, 2025 @07:07PM (#42617640)
> 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.