I’m sorry, but any non-trivial Zig code gives me PTSD flashbacks of C. I don’t understand who Zig is targeting: with pervasive mutability, manual allocation, and a lack of proper sum types, it feels like a step back from languages such as Rust. If it is indeed a different way to write code, one that embraces default memory unsafety, why would I choose it over C, which has decades of work behind it?Am I missing some context? I’d love to hear it.
sothatsit|6 months ago
Zig has become my go-to for projects where I would previously have reached for C, largely because Zig has such good compatibility with other C projects.
Rust, on the other hand, is a completely different beast. It is very different from C, and it is far more complicated. That makes it harder to justify using, whereas Zig is a very easy choice as an alternative to using C itself.
simonask|6 months ago
ozgrakkurt|6 months ago
Discriminated unions, error handling, comptime, defer.
Better default integer type casting, ability to choose between releaseSafe/releaseFast
And probably other things.
As for comparison to Rust, you do want very low level memory handling for writing databases as an example. It is extremely difficult to write low level libraries in Rust
simonask|6 months ago
kstenerud|6 months ago
Really? I've not found it at all difficult to write low level libraries in Rust.
flohofwoe|6 months ago
Do you consider Rust enums 'proper sum types'? If yes what are Zig's tagged unions missing?
E.g.:
kllrnohj|6 months ago
As for why you would choose it over C, because C has too many problems for even the C lovers to ignore. Zig fixes a tiny amount of them, just enough to pretend it's not problematic, but not enough to be useful in any non-hobby capacity. Which is fine, very few languages do achieve non-hobby status after all.
kristoff_it|6 months ago
[deleted]
LAC-Tech|6 months ago
People do systems programming in rust, but that's not really what most of the community is doing. And it's DEFINITELY not what the standard library is designed for.
konart|6 months ago
As someone who haven't done any systems programming after university: wait, what?
I was under impression that this is exactly what people where doing with Rust.(system apps, even linux kernel, no?)
If not - what do they (most if the community) are doing with Rust?
simonask|6 months ago
As far as I can tell, it contains many, many features that are irrelevant outside of systems programming scenarios with highly particular needs.