Why Not Rust?
I’ve recently read an article criticizing Rust, and, while it made a bunch of good points, I didn’t enjoy it — it was an easy to argue with piece.<br>In general, I feel that I can’t recommend an article criticizing Rust.<br>This is a shame — confronting drawbacks is important, and debunking low effort/miss informed attempts at critique sadly inoculates against actually good arguments.
So, here’s my attempt to argue against Rust:
Not All Programming is Systems Programming
Rust is a systems programming language.<br>It offers precise control over data layout and runtime behavior of the code, granting you maximal performance and flexibility.<br>Unlike other systems programming languages, it also provides memory safety — buggy programs terminate in a well-defined manner, instead of unleashing (potentially security-sensitive) undefined behavior.
However, in many (most) cases, one doesn’t need ultimate performance or control over hardware resources.<br>For these situations, modern managed languages like Kotlin or Go offer decent speed, enviable<br>time to performance, and are memory safe by virtue of using a garbage collector for dynamic memory management.
Complexity
Programmer’s time is valuable, and, if you pick Rust, expect to spend some of it on learning the ropes.<br>Rust community poured a lot of time into creating high-quality teaching materials, but the Rust language is big.<br>Even if a Rust implementation would provide value for you, you might not have resources to invest into growing the language expertise.
Rust’s price for improved control is the curse of choice:
struct Foo { bar: Bar }<br>struct Foo'a> { bar: &'a Bar }<br>struct Foo'a> { bar: &'a mut Bar }<br>struct Foo { bar: Box }<br>struct Foo { bar: Rc }<br>struct Foo { bar: Arc }
In Kotlin, you write class Foo(val bar: Bar), and proceed with solving your business problem.<br>In Rust, there are choices to be made, some important enough to have dedicated syntax.
All this complexity is there for a reason — we don’t know how to create a simpler memory safe low-level language.<br>But not every task requires a low-level language to solve it.
See also Why C++ Sails When the Vasa Sank.
Compile Times
Compile times are a multiplier for everything.<br>A program written in a slower to run but faster to compile programming language can be faster to run because the programmer will have more time to optimize!
Rust intentionally picked slow compilers in the generics dilemma.<br>This is not necessarily the end of the world (the resulting runtime performance improvements are real), but it does mean that you’ll have to fight tooth and nail for reasonable build times in larger projects.
rustc implements what is probably the most advanced incremental compilation algorithm in production compilers, but this feels a bit like fighting with language compilation model.
Unlike C++, Rust build is not embarrassingly parallel; the amount of parallelism is limited by length of the critical path in the dependency graph.<br>If you have 40+ cores to compile, this shows.
Rust also lacks an analog for the pimpl idiom, which means that changing a crate requires recompiling (and not just relinking) all of its reverse dependencies.
Maturity
Five years old, Rust is definitely a young language.<br>Even though its future looks bright, I will bet more money on “C will be around in ten years” than on “Rust will be around in ten years”<br>(See Lindy Effect).<br>If you are writing software to last decades, you should seriously consider risks associated with picking new technologies.<br>(But keep in mind that picking Java over Cobol for banking software in 90s retrospectively turned out to be the right choice).
There’s only one complete implementation of Rust — the rustc compiler.<br>The most advanced alternative implementation, mrustc, purposefully omits many static safety checks.<br>rustc at the moment supports only a single production-ready backend — LLVM.<br>Hence, its support for CPU architectures is narrower than that of C, which has GCC implementation as well as a number of vendor specific proprietary compilers.
Finally, Rust lacks an official specification.<br>The reference is a work in progress, and does not yet document all the fine implementation details.
Alternatives
There are other languages besides Rust in systems programming space, notably, C, C++, and Ada.
Modern C++ provides tools and guidelines for improving safety.<br>There’s even a proposal for a Rust-like lifetimes mechanism!<br>Unlike Rust, using these tools does not guarantee the absence of memory safety issues.<br>Modern C++ is safer, Rust is safe.<br>However, if you already maintain a large body of C++ code, it makes sense to check if following best practices and using sanitizers helps with security issues.<br>This is hard, but clearly is easier than rewriting in another language!
If you use C, you can use formal methods to prove the absence of undefined behaviors, or just exhaustively test everything.
Ada is memory safe if you don’t use dynamic memory (never call...