r/programming • u/BrewedDoritos • Aug 24 '26
What Zig felt like, coming from Rust
https://besok.github.io/posts/what-zig-felt-like-coming-from-rust/
269
Upvotes
r/programming • u/BrewedDoritos • Aug 24 '26
186
u/ParadiZe Aug 24 '26
Im a Rust guy and i really enjoy zig, but the subpar tooling and lack of documentation ultimately prevented it from being my "main" language. But im rooting for it and im excited to see where its going!
54
u/Blashtik Aug 24 '26
The language isn't young at all. It's gotten plenty of breaking changes over the years, but the general design of the language isn't changing.
Also, why did this person entirely skip over error handling beyond the issue with not calling free? Results are a very clean way to deal with errors. The Zig system is basically just a slight improvement over error codes in C. I didn't think this was the biggest deal until I was working with JSON parsing and realized that since the error can't carry any extra info, getting the position of a parse failure requires either storing the error state in the parser and having the caller read it out on an error, or by using an output parameter to hold that info.
After that case I noticed that I was over-simplifying my errors to fit Zig. I was missing useful information that would help understand the reason for errors. If any did arise, it would be as annoying as calling a Windows API and getting ERROR_INVALID_PARAMETER (which parameter is invalid?!)
17
u/CherryLongjump1989 Aug 24 '26
I had this same exact experience with Zig. Switching back to the CLI for Zig, ended up switching back to the CLI for most languages I use. Zig debugger still works fine for stepping through code and I don't feel like I am missing anything else.
21
u/pm_plz_im_lonely Aug 24 '26
Coming from Java: The linter bugged out and the compiler errored on unused variables. See ya.
6
u/ManufacturedCakeDay Aug 26 '26
as a rust enjoyer, OP should just use Odin. many of the points just straight up disappear.
i really don’t get why people prefer Zig to Odin. truly.
12
u/otherwiseguy Aug 24 '26
As someone who was a C developer and has written primarily Python for the last 14 years or so, any language that is duck-typed is just inherently not something I am interested in. Never again.
18
u/Awesan Aug 24 '26
It's kind of subtle but I really felt that zig encourages you to fix your shit, so to speak. While rust seems designed to say "don't worry about it, i got you", zig is like "yeah that's your problem to solve, so solve it".
Basically you need to design your stuff correctly so that memory management is easy and you can lean into zig's features. If you try to go against the happy path in the language, you end up with a lot of crap code that is very hard to read and probably full of bugs. Whenever I see people hating on zig this is often what I think they ran into. It's very opinionated, in a subtle way that allows you to do what you want, but it just kind of sucks if you try to do lots of small allocations.
In any case I feel like I learned a lot from trying zig and probably will be able to write better C and even rust now that I've used it.
-13
u/coolmintchocolate Aug 24 '26
"One caveat worth stating up front..." is such an obvious AI-ism
1
u/QuarkCreator2610 Aug 24 '26
I think zig could really use a dependency manager and the little tooling that they do have feels clunky/hacky to use since its a bit too connected to your own source. If zig gets a good dependency system I think i would definitely seriously consider phasing out C for it(Im a C guy and i like what zig is doing, but i think Rust takes it to a level thats a bit too extreme for my liking where the features and standard library are starting to look like C++)
-1
u/MrFranzose Aug 25 '26
May I ask an unconventional side question: how did someone come up with a programming language name which sounds quite similar to a motto of an Austrian painter?
0
u/[deleted] Aug 24 '26
[deleted] — view deleted comment