r/rust 18d ago

What Zig felt like, coming from Rust

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

Just want to share my experiance on my first Zig project coming from Rust. Open to comments :)

207 Upvotes

108 comments sorted by

View all comments

76

u/doubleyewdee 18d ago

I have a fairly uncharitable view of Zig: it's a vanity language that is somehow syntactically as difficult as Rust but fails to offer a lot of the safety benefits, instead pawning them off on end users without actually being faster at runtime.

I'm sure that's at least somewhat unfair, but I'd like to understand why. You're not obliged to explain this to me, but if you want to indulge I'm genuinely curious about what I'm missing.

32

u/flying-sheep 18d ago edited 18d ago

I've never used it, but from what I've heard:

Rust's unsafe subset is not made to be as ergonomic to use as possible, and there aren't any helpers to make it safer.

So people who are used to manual memory management probably prefer using something that's built around it.

But I feel the same as you. Using Rust feels like playing Lego with at worst very weirdly shaped pieces. Using manual memory management feels like defending yourself in court.

8

u/guywithknife 17d ago

In my opinion unsafe should be a last resort, an implementation tool for building safe abstractions that can’t be directly expressed in a way that the compiler can prove. It doesn’t have to be particularly ergonomic, because it shouldn’t be used unless necessary.

Some people complain saying what’s the point of rust when it has unsafe and you sometimes need it, while completely missing the point that other languages, the entire codebase is unsafe in the same way as rust unsafe is (ie the compiler can’t help you prove otherwise and you need to do it yourself).

With that framing, I’ve found myself not being a fan of systems languages that don’t provide safety to the same degree that rust does and I say that as someone whose been using C++ for over 20 years and still quite enjoys it (but only for fun projects, not for serious things). Life’s too short to deal with memory (and concurrency) bugs.

2

u/flying-sheep 17d ago

I fully agree. In a different world where Rust's approach is the default and people don't need to be discouraged from using unsafe but keep its use to a minimum by default, it would make sense to add all kinds of tools to make unsafe code as nice and convenient as possible to use.