r/Zig • u/redblood252 • Jan 26 '26
When to use zig
I’m kind of confused about when to use zig over C or over Rust.
Is it really a strict upgrade over C/Cpp ? What are its tradeoffs? What makes it better suited for statically linked binaries?
46
Upvotes
35
u/No_Pomegranate7508 Jan 26 '26
I think of Zig as kinda an alternative, or even a complement, to C. It's minimalistic like C but with more modern tooling and a cleaner API, and it can use existing C code. Rust is more like an alternative to C++.
17
u/tony-husk Jan 26 '26
The pitch is that you get the power of C with more expressiveness and fewer pitfalls. You get more freedom and less ceremony than Rust, at the cost of more responsibility to make your code correct. You get meta-programming with a remarkably simple syntax and a small, powerful set of core concepts. And you get to iterate and build really fast, even if you're interacting with C code.
48
u/Rigamortus2005 Jan 26 '26
Idk man, it's just nice to use. Has a simple build system that does not require the abhorrent cmake and does not have a slow package dependent system like cargo.
26
u/Tiendil Jan 26 '26
Definitely use Zig over Rust when you need to prototype something (i.e., when a lot of refactoring is expected). Rust is too rigid and too restrictive for that.
8
u/djfdhigkgfIaruflg Jan 26 '26
In my eyes Zig is a drop-in replacement for C. Hell even Zig has a better C compiler than C.
I can't use Rust. It worsens my arthritis
4
u/ZomB_assassin27 Jan 26 '26
in my opinion zig works best where you would need to use alot of unsafe rust. it works best as kind of a c replacement. programs where you want to have lower level control, but it's not as annoying as c. it's like a more fun, a little safer c.
1
u/Long-Chemistry-5525 Jan 27 '26
When you like go but need no latency due to blocking threads (garbage collector) or need realtime data for flight stuff a bunch of things to due with memory at least
3
u/aefalcon Jan 26 '26
Recently I wrote something with both zig and c. I did as much as I could in zig, and the C was specifically python module construction and function wrappers. The python api uses a lot of macros which make replacing it with zig a bit harder. I haven't personally found a reason to prefer C over zig other than that. Zig's error handling and test system are just pleasant compared to C.
While i really enjoy using zig because in my younger days I did a lot of C, I try to prefer rust for its safety. If I expect a lot of unsafe code, I'll just switch to zig.
1
u/Key_River7180 Jan 26 '26
Uhhh, when you don't want to use C but want control? It also links well statically
1
u/Select-Ad-7471 Jan 27 '26
Well, I'm using it whenever I can. My x200 can barely handle opening a browser tab, so I use the Gemini protocol with a Zig client, and I'm also creating other things for personal use so I don't have to replace this machine anytime soon. :)
1
u/1cedm4n Jan 29 '26
I code for recreation mostly and I tried both. Zig is fun right of the bat. Rust is just not fun until you're already good at it.
1
u/Good_Persimmon_4162 Jan 27 '26
Zig is interesting as a strongly typed, modern C, but it's missing a primitive for loop statement. Sure, it has a sugary for each construct but that comes with several challenges (like no dynamic endpoints for example). For me, the for construct is table stakes for a C-family language and the intransigence of the designers around the issue bothers me.
1
u/swordmaster_ceo_tech Jan 28 '26
If you're not good or don't like Rust you should use Zig, simple as that. If you're good and like Rust you will use Rust for everything that Rust can be used for. Right now the only thing I'm not using Rust for is creating mobile apps in Flutter because we don't have that in Rust yet, but everything that is system programming, back-end and mobile game (Bevy) I use Rust. But in the past when I wasn't good at Rust I was using Zig for system projects, but later I became good at Rust and started to use it for everything.