On Learning Rust š¦
Over the holidays I wrote Piet interpreter in Rust. Piet is an esoteric language where the programs are pictures. Iāve written some Rust in the past, but not enough to feel like I āgrokkedā the language. This was a good project that was meaty enough to get a good feel for the language but not too daunting for a beginner. Iām still certainly a newbie, but I think this post might be helpful for anybody else learning the language.
I view C++ (and maybe even Haskell) as prerequisites for Rust. A knowledge of C++ and RAII was essential for understanding how Rust does memory allocation. My background with Haskell and its type system and monadic approach to error handling carried over surprisingly well to Rust. Since Rust can be annoyingly pedantic about a lot of error handling, I imagine new programmers like myself will make frequent use of .unwrap()
. Two points helped me avoid this:
The ? operator is very similar to bind aka >>=.
Donāt be afraid to make your own error types.
The Rust ecosystem is still in flux. Especially with respect to async code. A few times I encountered compiler errors instructing me to use nightly for feature flags that I wouldāve expected to be enabled by default. When I get errors like this from the Haskell compiler, itās usually a sign Iām doing something wrong. In the case of Rust, there are just some really nice quality of life features on nightly that you shouldnāt be afraid to use.
The Python ecosystem adheres to the ābatteries includedā philosophy. Rust gives you some lithium and expects you to assemble those batteries yourself. For example, the minimal axum
web server described in the README.md requires use of axum
, tokio
, tower
, tower-http
, tracing
, tracing-subscriber
, and serde
ā each with their own set of idiosyncratic types, macros, and feature flags. I appreciate the flexibility that his provides over a more rigid framework (e.g.Ā Django), but it was a little daunting as someone new to the language. I would not recommend a web server as a good starting point for learning Rust. I learned this the hard way š
. The interpreter was a nice starting project: minimal external dependencies, easy to test, and self contained.
Overall, I was super pleased with Rust once I got over the relatively brutal learning curve. The compiler really gives really powerful guarantees about the memory safety of your code. No other mainstream language has done this before. I donāt think Rust will take over the world, but I see itās potential as a C/C++ replacement.