Why Learn Rust the Dangerous Way?

(Series Overview)

I think Rust is a great tool for C programmers to have in their arsenals. But Rust tutorials tend to start with higher-level concepts, focusing on what can be done with safe code and treating unsafe code as the exception. This can be alienating to us hardcore low-level programmers. It's like offering a course on blacksmithing but then spending all your time talking about how to clean chain mail — useful, maybe, but...didn't you skip some important steps?

In this series, I'm trying something different. Let's take a grungy, optimized, pointer-type-punning, SSE-using, heap-eschewing, warning-disabling C program and look at how we could create the same program in Rust. And I do mean the same program, without bounds checks or seatbelts, in all its unsafe glory.

Then, let's evolve it, by applying the features that Rust adds to C. We'll study the advantages and disadvantages at each step, thinking about how it affects both the code and our experience of working on the code. And as a ground rule: we won't let any step lose performance.

In the end, we'll wind up with a 95%-safe Rust program, immune to crashes and segfaults and buffer overflows, that's slightly faster than the original C program implementing the exact same algorithm.

What this isn't

This isn't a complete course on Rust — it's meant to complement other resources for learning the language. Read the Rust book to learn what Rust's features are; read this to put them in context with the low-level programming you already understand.

Experienced programmers can probably get a taste of Rust from this series even if you don't speak the language. If what I have to say piques your interest, it's time to go read the book.

Interested?

Head to section one: You can't write C in just any ol' language.