Week 10: Cheers to Rust!

Thanks for reading through this rollercoaster series documenting my learning process with Rust!

I have to admit that Rust is now one of my favorite languages, especially as I was learning it simultaneously to taking CS: 212, rated the most challenging CS class at Stanford, where I had to implement a Unix kernel (threads, syscalls, virtual memory, file system, cache, etc.) in C. While a really challenging project that I should write about at another point, there was many instances where I could simply compile code that to a certain extent looked like this:

struct thread* main_thread = malloc(sizeof(struct thread));
// setup the thread!
char* name = thread->name;
free(thread);

// time passes
printf("thread %s", name);

Ouch. Kernel panic.

Every time I debugged a simple semantic misunderstanding I had with the compiler like this, I would ask myself why the compiler would let me do this to myself, simultaneously muttering

“Rust would never let me do that.”

The rust compiler became the invisible mother that would scold me every morning that I didn’t make my bed. It made me think about the code I was writing, before I even hit the build button. I knew I would get hit by the proverbial red-error flip-flop.

The paradigm of ultra-strictness and genuine helpfulness that the compiler offers has made be grateful for the deep insights that modern compilers give to developers and makes me genuinely look over each warning (both in C and in Rust).

I also underestimated how beneficial a type system can be for not just memory safety, but also in functionality. For example, the serde package quickly allowed for the serialization/deserialization of most structs I made by simply tagging the definition with a #[derive(Default, Deserialize, Serialize)] macro. This enabled me to parse HTTP requests with ease, only needing a few lines of simple, readable code. On the other hand, the solution to serialization and deserialization is a non-obvious solution in Python or Javascript; everything is just some object, and its up to you as a developer to ensure exactly what object that is. Of course, there are ways to serialize and deserialize in all languages, but in Rust the solution is obvious, practical, and simple.

I hope to keep seeing the Rust community grow and hope that the growth of the language keeps pushing the frontier of development (especially for async/await ). I really hope I can do more web development with Rust in the future, building robust micro-services that can perform well with limited resources, and scale to infinity. Cheers to Rust in 2023!