Almost every thread about Rust for Linux ends up with someone saying "why not Zig instead"? And usually the answer is just "it's less mature" or "nobody pushed it".
I didn't know anything about Zig, so I decided to take a look today... and I'm not very impressed ^^;;
I learned that Zig does not have:
- Destructors
- Macros
- Lifetimes
- Operator overloading
Those are major reasons why I chose Rust for the drm/asahi driver...
It sounds like Zig is trying to be "modern C"... but the whole point of R4L is to not get stuck with C!
All those things Rust has that Zig doesn't are important for the things I'm doing.
Destructors/RAII are fundamental to how the driver tracks and cleans up firmware structures safely and reliably when needed. If I had to write "defer" everywhere it would be a bug-prone mess...
Rust's amazing macros are how I deal with the firmware versioning differences while keeping the driver maintainable. In C you can sort of do that (poorly) with the preprocessor... but Zig doesn't have that either, so that's actually a step back from C, as far as I can tell...!
I don't think I really need to explain lifetimes/memory safety, that's the one thing everyone knows is different between the languages... I'll just say, I am certain I wouldn't have gone from "first render" to "stable accelerated Linux desktop" in 2 days without memory safety.
(continued)
Operator overloading is the one I could live without... but it still would have been very annoying to have to use functions to do all the complex GPU power management calculations that I built on top of a simple soft float implementation (no real floats in the kernel!).
I have nothing against Zig, it looks like a neat programming language and it definitely has its place!
... but I don't think that place is writing complex operating systems and drivers today. At least I'm pretty sure it wouldn't have worked for my Apple GPU driver.
Edit: I'm getting a bunch of comments pointing out Zig's compile-time evaluation and metaprogramming features. I've looked into it a bit more, and so far my conclusion is "it's impressive and clearly very well designed and powerful... but for the very specific problem I'm personally trying to solve, Rust macros still work better"
Edit 2: People have come up with solutions to my versioning problem in Zig that are pretty similar to what I do in Rust with macros, so I'll retract that point. The other three still stand though, and the safety and destructors ones are pretty important ^^
Operator overloading is the one I could live without... but it still would have been very annoying to have to use functions to do all the complex GPU power management calculations that I built on top of a simple soft float implementation (no real floats in the kernel!).
I have nothing against Zig, it looks like a neat programming language and it definitely has its place!