- cross-posted to:
- [email protected]
- cross-posted to:
- [email protected]
There are endless debates online about Rust vs. Zig, this post explores a side of the argument I don’t think is mentioned enough.
Intro / TLDR
I was intrigued to learn that the Roc language rewrote their standard library from Rust to Zig. What made Zig the better option?
They wrote that they were using a lot of unsafe Rust and it was getting in their way. They also mentioned that Zig had “more tools for working in a memory-unsafe environment, such as reporting memory leaks in tests”, making the overall process much better.
So is Zig a better alternative to writing unsafe Rust?
I wanted to test this myself and see how hard unsafe Rust would be by building a project that required a substantial amount of unsafe code.
Then I would re-write the project in Zig to see if would be easier/better.
After I finished both versions, I found that the Zig implementation was safer, faster, and easier to write. I’ll share a bit about building both and what I learned.
Yeah, that is why I was calling out their title as click bait. Saying Rust vs Zig will mean most people think of safe rust vs zig. But the article is about unsafe rust vs zig which is a completely different story IMO. If you need lots of unsafe zig might be better - but the title does not say that. Hence IMO it is clickbaity.
Ok I will give you that for big projects. But this is on the other side of that. If you write two things in quick succession you will more likely still have the problems encountered in mind and be better able to navigate them the second time than if you are part of a large team that has had a lot of turn over since the project was first written. And you might make different mistakes - but the second round of mistakes is normally less impactful then the first set.
Oh yeah, of course this case I can see all that being true. But fundamentally they chose this problem because of that given they said:
Sounds like they want to compare unsafe rust with zig. They started with that idea which from my experience is not typical of most applications so their findings are not either.
Yeah that one might be.
Though unsafe rust overall is not a large amount of what rust code is, the author does seem to be picking the topic based on the hardest parts of rust and their title talks about all of rust which IMO is an unfair comparison. The story of zig being better than unsafe rust is interesting but only part of the whole zig vs rust debate.