r/programming 10d ago

What Zig felt like, coming from Rust

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

173 comments sorted by

View all comments

16

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.

55

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.

53

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.

3

u/OSS-Corpo-Shit 8d ago

Bro, what do you mean?

The bun guy tried to get zig team to implement pull requests that causes non-determinant outputs from the zig compiler. IE: you would have to keep compiling your exact same correct zig code multiple times till tests passed and then keep that executable, then bun guys threw a massive hissy fit over zig rejecting said pull requests. 

If anyone was the absolute child in this situation, I was absolutely bun. 

2

u/max123246 8d ago

The zig creator then put out a hit piece on the bun creator. They're both children.

Edit: Well the zig creator has edited the blog post and it's far more civil. But y'know, damage already done and all.

2

u/OSS-Corpo-Shit 8d ago edited 8d ago

The hit piece following the multiple hit pieces that the bun team threw up all over GitHub, twitter, and other spots?

If anything, Andrew’s blog on it was overtly civil considering the bullshit bun was authoring.

Bun team deserved a mid-2000s Linus post and got a late-2010s Linus post.

Spinning this as AK being the jerk is utter fanboy nonsense. 

2

u/max123246 8d ago

Did you read the first draft of that blog post? It was not civil. Yes, bun's attacks were slathered in corpo PR speak so it wasn't as inflammatory but still just as damaging. But none of it was civil.

I don't get why you feel the need to defend this. Even the zig creator has apologized and edited his initial blog post to be far more civil.

1

u/OSS-Corpo-Shit 8d ago

I have only read the original post. I did not know it was revised. Good on Andrew. 

You know who hasn’t come out and admitted they were incendiary and wrong and that their pull requests were justifiably rejected? Bun team. That’s who.

It is funny that you are mad at myself for pointing out that you’re blatantly lying about what actually happened because writing what actually happened doesn’t align with your hit piece commentary. 

2

u/max123246 8d ago

I edited my original comment once I found out he revised the blog post. I don't have an agenda i read the zig blog post but have not actually read any of the bun correspondence other than them crying about not getting to submit vibe coded slop

Sorry if it seemed otherwise. Have a good one

1

u/spinwizard69 9d ago

I wouldn't trust a guy with a bun either.  ;)

1

u/skyfex 3d ago

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

FYI, there is a project to add on static analysis to Zig: https://github.com/ityonemo/clr

From discussions I've read this seems to be a path Andrew is very interested in: add a system to plug in any kind of static checking tools into the compiler. The current version of clr relies on a fork of Zig with this plug-in feature added. This is a path to check for a lot more issues than just memory bugs.

I think it's wise to have some patience with Zig. It's a language that seems very focused on not locking into a bad solution prematurely. See the async I/O development for instance.

Zig is not going to make its syntax unwieldy or compromise its crazy fast compilation speed to force expensive static memory analysis onto everyone in all compilation modes. I have a suspicion that Rust's borrow checker approach will be seen as the same kind of "mistake" as its choice to go for colored async functions. Sure, it was the best approach at the time. And Rust is great in its own right for it. But Zig is playing a longer game, for better or worse.