4 ms·
Zig has defer, which is arguably way simpler. Is there something RAII can do that defer can't? Not everyone likes RAII by itself. Allocating and deallocating t
by Capricorn2481 2y ago
Zig has defer, which is arguably way simpler. Is there something RAII can do that defer can't?
Not everyone likes RAII by itself. Allocating and deallocating things one at a time is not always efficient. That is not the only way to use RAII but it's the most prevalent way.
- IX-103 2y agodefer can't emulate the destructors of objects that outlives their lexical scope. Return values and heap objects are examples of these since they outlive the function they were created in. defer only supports enqueuing actions at lexical boundaries. If you destroy an object that outlives the lexical scope it was created in, then you have to clean up manually.
- tcfhgj 2y agoDefer can be omitted