In the below podcast, Richard makes some interesting observations about the “rewrite it in Rust” meme. He claims that most practical applications of Rust and most libraries have a lot of unsafe code and those who claim Rust is a “safe” language likely have not used it extensively. There are large costs to Rust. Richard also questions if many of the problems with C++ could have been solved with better standard libraries that have array bounds checking, etc.
Loris contrasts this with the “maintain it in Zig” where you can take the C/C++ assets you already have, maintain them in Zig, which is a better build system, and then extend them into the future with Zig code.
Here is an example of the typical Rust message:
This discussion also makes me thing of Go’s “pure Go” approach. I’m sure there is also unsafe code in the Go standard libraries, but the emphasis is on not re-using C libraries, but rather re-writing things in pure Go, which is safe. Is this message different than the Rust message? I don’t know, but most things I need are available as pure Go and I really enjoy the stability and build system.
You have to say something really precise: Rust is the only systems level programming language that has a subset that is guaranteed at compile time to be memory safe. Even then, that subset is in practice calling unsafe code.
Languages Are like tools in a toolbox. The key is to know which one to use when. You will find fanboys of one over other and that doesn’t interest me as much. It’s easy to start using one tool to solve them all but that’s a limiting approach
Agreed! Richard has done a lot of Rust programming in the past couple years, so he’s very familiar with it, but he’s also a functional language fan, so that is probably his perspective.
Richard is also working on the Roc language, which the compiler is written in Rust.
Roc’s compiler has always been written in Rust. Roc’s standard library was briefly written in Rust, but was soon rewritten in Zig.
There were a few reasons for this rewrite.
We struggled to get Rust to emit LLVM bitcode in the format we needed, which is important so that LLVM can do whole-program optimizations across the standard library and compiled application.
Since the standard library has to interact with raw generated machine code (or LLVM bitcode), the Rust code unavoidably needed unsafe annotations all over the place. This made one of Rust’s biggest selling points inapplicable in this particular use case.
Given that Rust’s main selling points are inapplicable (its package ecosystem being another), Zig’s much faster compile times are a welcome benefit.
Zig has more tools for working in a memory-unsafe environment, such as reporting memory leaks in tests. These have been helpful in finding bugs that are out of scope for safe Rust.
The split of Rust for the compiler and Zig for the standard library has worked well so far, and there are no plans to change it.