In the recent months I’ve developed an interest for the Rust programming language. Some of its feature sound very attractive to me and while other people claim it to be just an improved C++ (like they say about C++ in regard to C) I try as much as possible to view it as its own thing. Of course from time to time I do comparisons between these two languages but I think that both are great tools for what they want to solve.

When I say to learn a language I mean to really learn it at the professional level not just to write some puny tools.

Coming from C++ to Rust

I think that when you work long enough in a specific language and then you want to learn another one you’ll inevitably use the language that you are more fluent in as a crutch. This can be both good and bad at the same time, the good thing being that you have the possibilty to learn much faster by mapping concepts that you know already to this new language and the bad thing being that you can carry habbits that while they work great in the language that you know better they are kind of an antipattern in the new one.

How I approach Rust (or any new language)

First of all I try to find some sort of reference or at least a book where I can find as many concepts as possible explained in good detail. At first I’ll just immerse myself into this reference, see what the language can do and want it can’t do; at some point I’ll just get overwhelmed with the details where I can’t make sense of them so I’ll just stop and I know it’s time to start building something to see how much I’ve really learned and what concepts need further polishing.

For the Rust programming language The Rust Reference is a great resource for this purpose. It’s well structured and straight to the point, language features are well presented and for most of them the reference has its fair share of code examples.

While reading through the reference I think it’s good practice to try and come with your own examples, see how you can break it, getting exposed to compiler errors it’s a good way of learning.

Of course if you’re going to use the language in a professional setting most likely you’ll have to work with other programmers, you’ll have to understand why some things are done the way they are and you’ll also notice some patterns. These patterns or idioms as they are usually referred to are a set of common practices that the community agrees over time it’s the “most correct” way of doing things. If you browse the source code for some number of projects written in Rust or any other language you’ll start to see them.

For this purpose I find Rust Design Patterns to be a good resource. It explains some of the general structures you’ll usually see in most code bases. For me it offered a pretty good explanation about how constructors/destructors are done in Rust and how RAII works in general. The Idiomatic Rust repository also offers a good amount of resources from which you can learn, well idiomatic Rust.

While reading all these resources and doing your own examples is already good nothing beats some exposure to a real world code base. I have an interest in asynchronous programming and naturally I’ve searched something along this interest and came across Tokio.rs. Not only this project has decent documentation but you can easily browse the source code.

Conclusion

To summarize: grab a reference, immerse in the details, try your own examples, break the language, develop your own mini projects, read well established code bases.

I hope you’ll find these resources as valuable as I do and I do hope that soon enough I’ll start writing posts that cover projects written in a decent enough Rust … and maybe a mixture of C++, we’ll see. :)