Rust as My First Language

Cover image

Who am I?

I'm an engineer who works in a field that is not related to software development. Computers are in my blood, I've been around them since I was a child. I can code and have danced with many tools over the years, but I'm not even remotely a professional. In the dark days of early COVID, I decided I wanted to learn how to code...really learn. I feel every engineer should know how to, as a means of expressing a solution to a problem. You might not do it every day, but it's a great tool to have in the belt.

Also, the notion of creating something from nothing has always fascinated me. This is what you do when you code, take a less than vague idea and turn it into a purposeful idea.

I set off on a self-taught journey.

Goals

I didn’t start out immediately with this goal, but it’s grown over time. I want to be able to make simple services for not only for myself but also the company I work for. I want to do this with an ecosystem that supports me and makes it relatively painless to get things done. I say relatively because there so no such thing as truly painless. Very often, you're picking your pain.

Why Rust?

As I started writing this piece, I started to feel really foolish. The feeling got worse the more I wrote.

I have no right to use Rust. Quite frankly it’s not necessary. I could work in anything that’s “easier”. Rust is not easy, the learning curve is legendary. The things it brings to the table are maximum overkill for literally anything I might want to create. I could use JavaScript, Go, C#, literally any garbage collected language.

Why Rust indeed.

I began the journey with the intent to sit down and learn C++ once and for all. Much of the world's most flexible software is written with it. I dipped a toe in, completing a very basic course on Codecademy. One thing that I kept thinking as I went along, I'm not smart enough, when the chips are down, to do anything meaningful in C++.

So, if not C++, then...what?

I spent time with vanilla web tech, including pure JavaScript, with a bit of dabbling into React, React Native, and NextJS. The trouble is, I dislike JavaScript...and I don't want to be the billionth person learning the traditional ways. I want to learn, use and advocate for something different. There are too many voices for the traditional tech stacks. I don't want to be part of that. I wanted something different.

Rust came onto my radar in early 2021. I installed it and began investigating. There are several aspects that drew, and continue to draw, me in.

Rules of the Road

Rust can go low and it can also go high. What I mean by that is you can get down into the dirt if you want, or you can stay up high with a web framework where someone else has dug in the dirt. The clear rules around memory use were really appealing to me. If I want to roll everything myself, I have a higher chance to create something safe out of the box, leaving me to worry mainly about logic errors. You get the power of C++ without the sleepless nights fretting about memory leaks, race conditions, and other nastiness.

Tooling

A struggle with Javascript is layer upon layer of tooling, that you have to cobble together from different places. Newer JavaScript runtimes, such as Bun and Deno, are making strides to solve this, but there’s still a level of mental overhead. In Rust land, you have cargo as your package manager. Once you start using it, nothing else is good enough. When you leave it, you immediately miss it its coherence.

Pair Programming

The Rust compiler is very tough, but in a good way. Out of the box you have an immediate ally and pair programmer sitting beside you. I've learned a lot from it. I miss it when it’s gone. Clippy, Rust’s linter, is ready and waiting too, offering rich, helpful suggestions.

Testing

This may be a cliche, but testing is a first-class concept in Rust land. You don’t have to do anything special or pull in anything external to write tests. As a new, sole “developer” I need to be diligent and write tests. The fact it’s so easy is really appealing.

The Challenge

Rust is technically challenging. It presents a terrific puzzle to solve. Yes, it can be frustrating and at times can impede your progress, but the feeling when you get the pieces together is second to none. The feeling when you can just sit down and get some Rust code down to accomplish something is really wonderful.

My Approach to Learning

Early Days

I’ve always been someone who learns by example. Reading theory and trying to build straight from that has always been a challenge. I get bored quickly just exploring the individual building blocks. I need to see an end goal, then I go about putting together the pieces, breaking them down and gaining insight along the way.

When I started in early 2021, there weren’t a lot of learning materials from which to gain context and best practices. I used Medium articles quite a bit, and made my first attempt to get through the Rust Book, which of course, is the consensus starting point. In these early days, the power and point of the type system wasn’t quite visible. I found the basics of Rust similar to C, which I knew a little from the past, so this was an early hook.

I did drift away from time to time, as I do suffer from "grass is greener, maybe "X" is easier syndrome", trying out other corners and other languages. However, Rust had made a mark on me and I always kept an eye on it. The promises it brought to the table we too great to overlook.

Zero to Mastery

I came to realize I wasn’t achieving anything by dancing around. I wanted to get back to Rust. I decided I needed a course, enter Zero to Mastery and the Rust course by Jayson Lennon. I enrolled in March 2022 and spent the next few months working through his amazing course. It's taught like a beginner programming course, building up from the very basics. I highly recommend it. Jayson is a fantastic teacher. He's very active and supportive on the Zero to Mastery Discord.

Zero to Production in Rust

I attempted to work through Zero to Production in Rust, by Luca Palmieri before fully completing the Zero to Mastery Rust course. It was a mistake, for two reasons, a) I wasn’t ready and b) I rushed too much and didn’t focus on the journey. In early 2023, I returned to it again, this time pushing myself to use a different web framework, Axum instead of Actix Web. This turned out to be an excellent move. It was challenging for sure, and admittedly, the unfortunate tendency to rush to the finished "thing" was still there, but it made me think and engage more. I had to start getting acquainted with crate documentation in order to figure out and implement the steps of the project. I highly recommend "ZerotoProd", it's an essential step for new Rustaceans.

Contributing to Open Source

Somewhere early in 2023, I discovered Shuttle. Re-discovered is maybe better, as I as aware of the project since late 2022. Again, I dove in with both feet and started helping with their documentation. In the summer of 2023, I tentatively put my name down to actually work in the Shuttle codebase. I helped implement a few new methods for Shuttle Persist. I felt so stupid, banging my head for hours sometimes, slinging code hoping something would stick. The Shuttle Team was so gracious, quietly coaching and pointing the way. The work I did really helped with some things I was struggling with, chief of which was testing. I had to learn how to write unit tests to support the code I added. I'm sure the Team have re-factored and thrown away what I originally wrote by now, but seeing it committed and in the codebase was a wonderful feeling. Contributing to open source...to something real, was an essential step in the journey. I continue to help with simple things and nurse the desire to, someday, really help with a big new feature.

Shuttle Christmas Code Hunt

In December 2023, the Shuttle folks started the first ever “Christmas Code Hunt”, in the vein of Advent of Code. In contrast to that, the Shuttle challenges were far more approachable. At first, I thought, I’ll add to the challenge by using Tower, rather than a higher level web framework. By this time, crate documentation was less mystical to me, and I figured out enough theory that I felt I could get somewhere. I did…mostly. With a bit of kind community help, I completed the first few challenges before dropping off. I intend to return to these challenges in the future.

Iteration, Diffusion and Consistency

Overall, iteration and repetition are key to me learning anything, especially Rust. I repeat things, perhaps with small variations, that build muscle memory. I can now organize a project into a binary and library, with modules, effortlessly. Project organization was difficult at first, understanding file and folder boundaries, and how Rust treats them, was a challenge. The material in the Rust Book was abstract for my liking, lacking in specific, practical examples. Once it clicked, it suddenly became very logical.

What I think of as diffusion, or diffuse learning, was important too. You really do have to let your brain absorb and process things over time. It's nice to have little moments where something you struggled with for months suddenly clicks and becomes second nature. This can only happen if you give the brain time to sit back and process.

Consistency is the last piece. I've done something with coding literally almost every single day since I started in late 2020. Don't underestimate how small steps over a long period of time add up to something great.

Path Forward

I will continue to use Rust wherever I can. My journey with it has been a pleasant challenge. There have been moments of frustration and drift, but I really am enjoying the journey. I haven't made much for myself personally, but am working on using Rust at work. The project I'm most proud of is a sort of "availability tracker" for staff to use that indicates their availability to take on more work. It also lets them show upcoming vacation time, so that others can plan accordingly. I built this app with Actix Web on the backend, which serves up a Tera template for the UI. A Postgres database saves all the information which is displayed by Tera template. I've also embarked on a redo of our office intranet site, which I initially did in React, but going forward it will be done with Yew, which is a very pleasant Rust frontend framework. The project will solidfy my knowledge of form handling and fetching in Yew. I'm also figuring out how to leverage the wasm-bindgen crate to step back and forth between Rust and JavaScript.

Closing Thoughts

I'm no computer scientist or full fledged software developer, I realize the thoughts in this piece are probably a little thin and my rationale for choosing Rust may come across as a little contrived. There are a lot of tools out there and I could have easily picked anything. If Rust didn’t exist, I’d probably just be in JavaScript like everyone else, blissfully unaware. However, I’m happy there's a choice. I love that there exists a tool that takes whole classes of bugs off the table and supports me in the desire to create quality, efficient, and safe software.

Although I'm not the most qualified person in the world at Rust programming, I will continue to advocate for its use and adoption. I would encourage anyone interested to dive in head first and carve a unique path.

Shameless Self-Promotion

I'm on the umpteenth iteration of my blog, the latest is at: jeff-mitchell.dev. Here you'll find everything I've written so far in the journey to learn Rust. I want it to be a "go to" for the examples, explanation, and context I didn't have when I was starting out. I was roughly blogging through the Rust Book, so you'll see more continuation of that soon.

I hope you find something of use in my words!

This blog post is powered by shuttle - The Rust-native, open source, cloud development platform. If you have any questions, or want to provide feedback, join our Discord server!
Share article
rocket

Build the Future of Backend Development with us

Join the movement and help revolutionize the world of backend development. Together, we can create the future!