From the README:
> Memory safety with RAII patterns
I'm curious to see how they achieve RAII in Zig, which doesn't have destructors. If they mean defer + deinit methods, that's not the same thing.
From the README:
> Memory safety with RAII patterns
I'm curious to see how they achieve RAII in Zig, which doesn't have destructors. If they mean defer + deinit methods, that's not the same thing.
> If they mean defer + deinit methods, that's not the same thing.
No? It's the first thing that came to my mind when I've read RAII.
You have to call defer after initialization so you can’t technically call it RAII. As long as you remember to call it then it is effectively the same. Personally defer makes it so very similar to be a difference without a distinction but the “is initialization” part can’t be true if you need to do a second step.
Zig is all about making things explicit. Destructors are hidden code. I presume there will be an application level tracking of lifetime.
Yes, which is why Zig can't have RAII. Zig initialisation and destruction are fundamentally different to how RAII works in other languages. That's not a negative point; it's just how Zig is. But it's not RAII.
You are right. It seems the developer agrees and has changed the README
It's explicit opt in RAII, you opt in by using a defer.
RAII, which stands for Resource Acquisition Is Initialization, is a programming technique in which a resource's lifetime is tied to an object's lifespan. An explicit defer does not fit this paradigm.
free is an explicit opt-in garbage collector.