Live data from Hacker News

When Zig Is Safer and Faster Than Rust

zackoverflow.dev

1–10 of 58 posts

Re: When Zig Is Safer and Faster Than Rust

#4
Zig has a singular focus on doing low level systems programming and it shows.

Rust is very nice for systems programming, but it's not as ergonomic as Zig at all. Of course, it's a much nicer and more comfortable general purpose language.

I think both languages are great and hope to see them used more and more in the future. It's much better to debate when to use Zig and when to use Rust then go back to the dark days of C and C++.

Re: When Zig Is Safer and Faster Than Rust

#6
> The garbage collection is the important part, it’s hard to make it work and be fast and be safe because its fundamentally a problem that doesn’t play nicely with the borrow checker.

That's fair, use the right tool for the right problem. For most applications you can just use a garbage collected language after all.

Re: When Zig Is Safer and Faster Than Rust

#7
Apart from syntax sugar over which I agree should be improved, the argument sells to boil down to: my language doesn't enforce a borrow checker so it is UB safe. Which in my book is just not true.

The allocator example the user gives is not really good since if he had another try in between the alloc/free I assume the memory would not be freed, Drop semantic is better in that regard. You can also set a global alloc that check for missing free in rust though probably not as nice as a localized one.

Re: When Zig Is Safer and Faster Than Rust

#8
> Rust’s raw pointer types are nullable by default and have no null-pointer dereference checking. There is a NonNull pointer type that gives you more safety. I’m not sure why it’s not the default, since Rust’s references are non-nullable.

NonNull would probably be a better default indeed, but one reason might be that NonNull has more UB than *mut T (namely, it is UB for it to be the null pointer).

(A lot of the text is about how more UB makes unsafe programming harder, which is a fair point)

> Zig pointers, by default, are non-null and you opt-in to nullability using the ? syntax (e.g. ?*Value). And of course, you get null pointer dereference checking enabled by default too.

Well so Zig pointers, by default, has more UB than Rust pointers, at least when concerning null pointers.

Re: When Zig Is Safer and Faster Than Rust

#9
post #6

> The garbage collection is the important part, it’s hard to make it work and be fast and be safe because its fundamentally a problem that doesn’t play nicely with the borrow checker. That's fair, use the right tool for the right problem. For most applications you can just use a garbage collected language after all.

For a pure Rust answer to “how to make a primarily-safe gc-lang in Rust”, see Piccolo (Lua) with its ‘Stackless VM’:

https://github.com/kyren/piccolo

That’s not to say Piccolo couldn’t theoretically benefit from having its (already isolated) unsafe parts rewritten in Zig, but that’s up to the Zig developer community to chip away at with upstream contributions.

Re: When Zig Is Safer and Faster Than Rust

#10

> Rust’s raw pointer types are nullable by default and have no null-pointer dereference checking. There is a NonNull pointer type that gives you more safety. I’m not sure why it’s not the default, since Rust’s references are non-nullable. NonNull would probably be a better default indeed, but one reason might be that NonNull has more UB than *mut T (namely, it is UB for it to be the null pointer). (A lot of the text…

there is no UB in zig pointers in ReleaseSafe compilation mode.
Post reply on HN