Why I rewrote my Rust keyboard firmware in Zig: consistency, mastery, and fun
&gt; much of the complexity I’d unconsciously attributed to the domain — “this is what systems programming is like” — was in fact a consequence of deliberate Rust design decisions.<p>This is something I&#x27;ve thought a lot about as I&#x27;ve started to reach the &quot;hundreds of hours&quot; of working with Rust mark. Besides attributing the complexity of Rust to the domain of systems programming, I think a lot of Rust&#x27;s complexity often gets attributed as a trade-of you&#x27;re making for the safety guarantees afforded by the borrow checker. But I think a lot of the complexity in Rust is not related to the borrow checker at all, and is just a result of certain design decisions in the language.<p>For instance, taking the module system as an example, in general, I can declare a dependency in mu `Cargo.toml` file like this: `&quot;crate_name&quot;`, and then import it into a given source file using the use declaration: `use crate_name`. However there&#x27;s a special case, where if the crate name uses dashes, like `&quot;crate-name&quot;`, then the compiler will implicitly resolve to that from a use declaration using underscores: `use crate_name`.<p>Similarly, if wade into an unfamiliar code-base, and I see a use declaration like this: `use path::to::foo&quot;, if I want to look for the code for this, it could be in one of three places:<p>1. The file `src&#x2F;path&#x2F;to&#x2F;foo.rs`<p>2. The file `src&#x2F;path&#x2F;to&#x2F;foo&#x2F;mod.rs`<p>3. Some other file, based on re-export via a `pub use` declaration.<p>So in order to use Rust effectively, I have to just sort of know about all these implicit behaviors of the compiler, and in my experience it took months to learn enough of these tricks and corners to really just be able to sit down with an idea and start coding in Rust without consulting documentation and examples regularly. And even after that the compiler still surprises me sometimes.
To give another example of somewhat vexing implicit behavior which does relate to the ownership system, just today I had a block of code which looked like this:<p><pre><code>    let x = some_value;
    match x { ... }
    x = some_other_value;
    match x { ... }
</code></pre>
Which compiled fine. And then by commenting out the second assignment of `x`:<p><pre><code>    let x = some_value;
    match x { ... }
    &#x2F;&#x2F; x = some_other_value;
    match x { ... } &#x2F;&#x2F; &lt;-- use after move
</code></pre>
suddenly I had an ownership error, because `x` was moved by the first match statement. So here what was really going on is that the compiler was &quot;helping me&quot; using implicit rules to establish that `x` was referring to a different memory location after the assignment. It&#x27;s an example of how Rust has all these implicit behaviors and overlaid systems which are intended to make working in a borrow-checked context easier, but in practice what this often means is that when you change something in such a way that one of these implicit systems breaks down, it can cause a failure in what seems like a totally unrelated place, which can be very surprising.<p>I wonder if part of this has to do with the fact that Rust seems to appeal to a certain type of programmer who is attracted to esoteric topics and arcane knowledge, so the fact that Rust is essentially an unlimited well of complexity is more a feature than a bug to them. But I have been thinking a lot about what a programming language would look like which has an ownership system like Rust, algebraic types, and a trait system, but puts a ruthless emphasis on productivity and eschewing complexity.