←back to thread

135 points barddoo | 9 comments | | HN request time: 0.014s | source | bottom

Writing Redis from scratch in Zig.
Show context
tcfhgj ◴[] No.45308065[source]
So riiR is now riiZ? ;)
replies(1): >>45308745 #
1. nine_k ◴[] No.45308745[source]
"Rewrite it away from C (or C++)". Whether you choose Rust, Zig, Ada, D, Nim, even Pascal, it's likely going to become more secure. It will be supported on fewer platforms though, but still should run fine under Linux, macOS, Windows, *BSD, on x64, Arm64, and likely RISC-V, too.
replies(1): >>45309389 #
2. maleldil ◴[] No.45309389[source]
Zig isn't memory safe, though. It's safer than C or C++, but not much.
replies(2): >>45309760 #>>45309844 #
3. ashikns ◴[] No.45309760[source]
This is what I have struggled to understand about Zig. It seems pretty much like C in a mental model aspect - you are responsible for everything. It's slightly better than C, but C already runs on everything on the planet and can be made secure even if painfully so. So what niche is Zig aiming to fill?
replies(2): >>45309865 #>>45309942 #
4. throwawaymaths ◴[] No.45309844[source]
checked array bounds is memory safety.
replies(1): >>45311001 #
5. throwawaymaths ◴[] No.45309865{3}[source]
no, null pointers are enforced safe at the type level in zig, as are array bounds, this eliminates huge classes of errors, so you are not "responsible for everything". unlike c, you often (unless highly tuned performance is needed) do not have to resort to opaque void pointers, and the compiler gives you typesafety on that, another major footgun in c.

also operators and integer types are unambiguous, and there is no UB in safe compilation modes.

It's arguably much better than C, not "slightly better than C"

replies(2): >>45310566 #>>45310735 #
6. barddoo ◴[] No.45309942{3}[source]
Zig detects memory leaks pretty well when you build it using -Doptimize=Debug.
7. ◴[] No.45310566{4}[source]
8. uecker ◴[] No.45310735{4}[source]
If you write a modern style of C, you can have bounds checked code and do not need to use void pointers. I usually find that people overestimate the advantages of newer languages compared to using C by comparing to old and badly written C.
9. lyu07282 ◴[] No.45311001{3}[source]
Runtime bounds checking, but only in Debug/ReleaseSafe builds, besides there are many other types of memory safety issues left unaddressed.