←back to thread

135 points barddoo | 5 comments | | HN request time: 0.577s | source

Writing Redis from scratch in Zig.
1. maleldil ◴[] No.45309397[source]
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.

replies(2): >>45309688 #>>45310719 #
2. justinhj ◴[] No.45309688[source]
Zig is all about making things explicit. Destructors are hidden code. I presume there will be an application level tracking of lifetime.
replies(1): >>45310538 #
3. ◴[] No.45310538[source]
4. teo_zero ◴[] No.45310719[source]
> 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.

replies(1): >>45313193 #
5. rokob ◴[] No.45313193[source]
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.