←back to thread

143 points barddoo | 1 comments | | HN request time: 0.202s | source

Writing Redis from scratch in Zig.
Show context
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 #
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 #
1. 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.