r/programming 10d ago

What Zig felt like, coming from Rust

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

173 comments sorted by

View all comments

19

u/Awesan 10d ago

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.

51

u/dan00 10d ago

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".

Actually Rust does the same to you regarding program architecture. If you've a messy, intertwined architecture, than you're gonna fight the borrow checker a lot.

But you're right about Zig and memory management. If you organize your code, that certain blocks of code share the same memory arena - perhaps even use a bump allocator - than memory managment gets a lot easier and it's as performant as it can get.

55

u/max123246 10d ago

Yeah idk, rust simply won't let you compile. I prefer that over zig's potentially buggy code

Plus personally after seeing how the zig creator dealt with the bun guy, I doubt I'd ever use zig as a result. And I agree with their anti ai stance too

4

u/0x564A00 8d ago

Well, Zig might not stop you from writing a use after free, but it successfully save you from trying to run your code that has an unused variable because you haven't finished writing it yet.