Want to learn Zig, but Rust's memory safety is too good. What should I choose?
Posted by hireme-plz@reddit | learnprogramming | View on Reddit | 16 comments
I'm planning a performance-focused project and wanted to learn Zig. But Rust's memory safety and reliability seem too good to ignore.
What are most people choosing these days for performance-critical projects?
_N-iX_@reddit
Rust and Zig are solving slightly different problems even though people compare them constantly. Rust optimizes heavily for safety and correctness, while Zig optimizes more for simplicity, explicitness and developer control.
For performance-critical systems where reliability matters a lot - servers, infrastructure, distributed systems, security-sensitive software - Rust is currently the safer industry bet. But Zig is becoming attractive for low-level tooling, embedded work, game engines and places where people want predictable control without the complexity of C++.
mlugo02@reddit
Go with Zig. With its own arena allocators, that should solve around 90% of any memory management you’ll ever need.
hireme-plz@reddit (OP)
Can it compete with Rust’s ownership model?
bowbahdoe@reddit
So there are different priorities involved here. Rust's memory model adds non-trivial costs in other places. Learning curve (not just first time learning curve, when reading code bases that step into the strange lifetimes realm), compile times, language complexity, etc.
Zig makes issues less likely by construction as compared to C - both languages do - but it picks a different point on the "likelihood of issue/language complexity" spectrum.
SV-97@reddit
No, absolutely not
bowbahdoe@reddit
This is always wild to me - just learn both. Whenever you think you want to learn something that's when you learn it. If you feel like you need to order them then sure whatever, but ultimately and just learned both of those things and everything people mentioned in the comments here.
That's how you get good
ParadiZe@reddit
you use rust for the type system, not memory safety
Savings_Discount_230@reddit
rust if you want a job, zig if you want a hobby. borrow checker feels like a nanny until you ship something that doesn't crash for 3 months. zig's comptime is wild though.
SV-97@reddit
Most people are still choosing C, Fortran and C++ (and cuda etc.). If they don't care about performance as much also Go, C#, Java, maybe even Python with lots of native extensions (numpy, cupy, polars, fenics etc.), ...
Personally I'd choose Rust whenever its an option (and indeed it's what I'm exclusively using at my job around scientific computing), and I would basically never choose Zig. There's no point in going fast if your code isn't actually correct; and Rust fosters correctness and speed at the same time.
neveralone59@reddit
Rust. Zig is cool for c interop and stuff you’d normally use c for. Rust is way more flexible
hireme-plz@reddit (OP)
What do you mean by flexibility?
neveralone59@reddit
Rust is substantially more expressive than zig. If you think the best part of rust is ownership/lifetimes/borrowing then you should lean into the type system a bit more. Traits are without a doubt my favourite abstraction, they’re far better than classes for most things as you don’t have to do any inheritance, just provide impl blocks for things. Also being able to chain composable functions feels so good. The features it borrows from ML/Haskell are by far the best parts.
You can write rust in a similar way to how you would write c, but I think you’re really limiting yourself if you do this.
stdmemswap@reddit
Adding to above:
Expresiveness: you can tell more high level story and put more meaning with less (symbols).
Also, cargo is much more mature, rust is more production ready.
dacian88@reddit
It’s production ready vs not, unless you’re doing this for academic reasons
Achereto@reddit
You could go with Odin instead. Odin is a low level language like zig, but a bit less verbose.
significantairport9@reddit
C++