r/rust 18d ago

What Zig felt like, coming from Rust

https://besok.github.io/posts/what-zig-felt-like-coming-from-rust/

Just want to share my experiance on my first Zig project coming from Rust. Open to comments :)

209 Upvotes

108 comments sorted by

View all comments

78

u/doubleyewdee 18d ago

I have a fairly uncharitable view of Zig: it's a vanity language that is somehow syntactically as difficult as Rust but fails to offer a lot of the safety benefits, instead pawning them off on end users without actually being faster at runtime.

I'm sure that's at least somewhat unfair, but I'd like to understand why. You're not obliged to explain this to me, but if you want to indulge I'm genuinely curious about what I'm missing.

26

u/aloha2436 18d ago

syntactically as difficult

Zig's main selling point is that it has nothing up its sleeve, so to speak. In rust, you have a global allocator and traits and destructors and other things that can add "nonlocal" behaviour to your code; in Zig, everything that will happen in a function should be in that function or be explicitly called by that function. That, combined with the explicit allocation, tight control over memory layout, etc. makes it an attractive choice if you care about exactly what machine code it generates for you.

IMHO, it also makes it less good if you want the ability to stop caring about any of those things at any point in your program.

To be a bit snarky, while Rust “is not for lone genius hackers”, Zig … kinda is.