What a way to run a rodeo


Learning Rust

published:

tags: [ #code ]

I've been noodling around with the Rust programming language. Mainly just writing a glorified CS 101 console app, some console I/O, some file I/O, a little SQLite database. I'm not the kind of coder that likes doing this for fun in their spare time, but I wanted a little doohickey to make something easier for me, and so I thought hey why not try out this whole Rust thing.

Not super in love with it, so far.

There's a lot of hand-wringing articles about going to Rust from C++ about needing to understand the ownership model, but I have zero issues with that. It's mostly that I just hate the syntax1, and find it quite annoying to read. All these Options and question marks and unwraps and maps and matches and ok_ors, blah blah blah. That's not something I'm going to fight about2 though, it is the sort of thing that I would eventually be able to read/write as second nature, with more experience than I have now (or will ever get, realistically.)

The big selling feature is of course the memory safety guarantees, which come as a result of the ownership model and the move-by-default nature of things, as far as I can tell. I'm not sure it moves the needle for me, as I think you get more or less the same out of "properly"3 written C++ (embrace value-semantics and RAII4, aggressively pursuing const correctness, avoid raw pointers, do not be afraid of templates). Either way, the objective is to turn bugs into compile errors, and Rust is stricter in enforcement of things, where C++ would leave it to you to ignore the linter warnings at your peril.

But the whole exercise has me reflecting on just how poorly C++ was taught to me in school, and just how much C++ code I've dealt with professionally looks like it came out of similar education systems. Very much the pejorative "C with classes", and it's this approach to the language that leads to such shoddy output, in my experience. Took me several years to extract my own mindset out of that soup. So that's the real benefit that Rust brings, to my mind: if you were learning how to program today with Rust, then the compiler will teach you how to manage memory safely pretty much by definition. I'd be surprised if C++ was even taught in university or college today, let alone by an actual battle-hardened C++ dev instead of an underpaid, overworked TA.

I still think it's ugly though.


  1. Yes I can appreciate the irony of being a C++ guy complaining about ugly syntax. Whisper but actually it's the children who are wrong.

  2. But I'm not above cherry picking a random blog post that agrees with me.

  3. According to me.

  4. The absolute dumbest of acronyms.