News for hackers. Stuff that matters.
Re:Defer Available in GCC and Clang by miguel_martin on Friday February 20, 2026 @04:09AM (#47085528)
defer is literally just an explicit RAII in this example. That is, it's just unnecessary boiler plate to wrap the newResource handle into a struct in this context.

In addition, RAII has it's own complexities that need to be dealt with now, i.e. move semantics, which obviously C does not have nor will it likely ever.

Re:Defer Available in GCC and Clang by maccard on Friday February 20, 2026 @06:23AM (#47086582)
> RAII has it's own complexities that need to be dealt with now, i.e. move semantics, which obviously C does not have nor will it likely ever.

In the example above, the question of "do I put defer before or after the `if err != nil` check" is deferred to the programmer. RAII forces you to handle the complexity, defer lets you shoot yourself in the foot.