logoalt Hacker News

kjgkjhfkjftoday at 5:33 AM5 repliesview on HN

The article is a bit dense, but what it's announcing is effectively golang's `defer` (with extra braces) or a limited form of C++'s RAII (with much less boilerplate).

Both RAII and `defer` have proven to be highly useful in real-world code. This seems like a good addition to the C language that I hope makes it into the standard.


Replies

Zambytetoday at 5:50 AM

Probably closer to defer in Zig than in Go, I would imagine. Defer in Go executes when the function deferred within returns; defer in Zig executes when the scope deferred within exits.

show 4 replies
L-4today at 7:57 AM

Both defer and RAII have proven to be useful, but RAII has also proven to be quite harmful in cases, in the limit introducing a lot of hidden control flow.

I think that defer is actually limited in ways that are good - I don't see it introducing surprising control flow in the same way.

show 2 replies
omoikanetoday at 5:00 PM

> with extra braces

The extra braces appear to be optional according to the examples in https://www.open-std.org/JTC1/SC22/WG14/www/docs/n3734.pdf (see pages 13-14)

throwaway27448today at 10:02 AM

This certainly isn't RAII—the term is quite literal, Resource Acquisition Is Initialization, rather than calling code as the scope exits. This is the latter of course, not the former.

show 2 replies
usrnmtoday at 10:23 AM

To be fair, RAII is so much more than just automatic cleanup. It's a shame how misunderstood this idea has become over the years

show 1 reply