After a week with Rust

I personally think that Rust calling &uniq references mutable references with the &mut is a big "lie" which ends up biting the programmer back as soon as they start using more subtle stuff:

  • For instance, most people are astonished that the following program fails to compile:

    let mut x = 0;
    let mut inc_x = || { x += 1 };
    inc_x();
    dbg!(x);
    inc_x();
    dbg!(x);
    

Rust has multiple unique paradigms that don't even exist in other languages, such as lifetimes and compile-time-tracked "exclusive access". But instead of endorsing them from the beginning, as @mbrubeck's Rust: a unique perspective does, the Rust book tries to show a language that is "like other languages, but with (magical) compile-time checks". When the truth is that Rust's strength lies in non-unsafe Rust being less expressive than languages like C or C++.


I think that Rust should start with that statement: "Welcome to a language that by being less expressive forces you to use contructs that are guaranteed at compile-time to be sound. But don't worry, after some time you will get used to the coding patterns that are allowed, and will then almost not notice the hindered expressiveness, only the enhanced zero-cost safety that will let you hack without fear".

  • It doesn't sound bad imho, and is at least honest w.r.t. the struggles that someone refusing to shift their way of coding / mental coding patterns may encounter.
12 Likes