logoalt Hacker News

reactordevtoday at 12:44 AM4 repliesview on HN

which is a good thing. C++'s RAII is magic-sauce that does a lot for you when you can simply use `defer` in zig. A constructor is just a function call. A destructor is just a function call.


Replies

shakowtoday at 1:09 AM

And a function call is just a fancy JMP, still it's generally acknowledged to be better to have all the bookkeeping automated.

rcxdudetoday at 10:24 AM

Does defer in zig track the objects lifetime directly, or is it like the various other 'context' features in other languages where it only really works for lifetimes of function-local variables and leaves you on your own when things get more complicated? (which, IMO, is precisely when RAII becomes most useful. It does seem like most of these languages only consider the 'forgetting to cleanup on an early return from a function' case)

nlytoday at 10:12 AM

Constructors and destructors are also just function calls in C++

And you can't forget to type defer

fookertoday at 1:31 AM

How is defer not magic sauce?

show 1 reply