Really basic question - for those of you in here w...
# random
b
Really basic question - for those of you in here who work with the Pants Rust codebase, what were effective resources to learn Rust as a beginner? I’ve been trying to do Advent of Code challenges using Rust (this was a mistake) and I feel like even very basic stuff is unusually challenging for me to understand.
c
interestingly enough I’m sitting here contemplating doing this years advent of code in rust for the sake of getting to know rust better 🙂
(so I had nothing useful to say, sorry 😅 )
b
Lol no worries. I feel like in certain languages it’s easy to just sort of shoot from the hip and just get to the correct answer over time with some iteration (at least, I found myself able to do this with Go/Java). But I feel like with Rust this has been way more of a challenge and I can’t just YOLO my way to the correct solution
c
lol- interesting, makes me almost more intrigued to try it now 😀
h
The "official" rust book is a good place to start: https://doc.rust-lang.org/book/
👍 1
And then the O'Reilly book is a good supplement to it
Yeah, Rust is one of those languages where you need to do the reading. You can't just cargo-cult across.
👍 1
w
I’ve always been a dive-in and hope kinda guy :) Helps having a C++ background a decent amount, as there weren’t really any unfamiliar concepts - just variants on a theme with some new grammar. I was able to put a decent embedded system into production in Rust while learning along the way - the rust “book”, and the embedded rust “book” were the go-to resources by a mile. Completely anecdotal - but I found a lot of the misc code online (blogs, stack overflow, etc) weren’t actually that great. Maybe it’s just me, but I got the feel that a lot of those code sources were trying to “show off” how fancy they could make rust. A lot less pragmatic than I’m used to when googling other languages 🤷‍♂️
g
In the same camp as SJ -- when I joined my current employer, I hadn't written a single line of Rust before, and started on a Rust-only project. First project was writing animation controllers + integrating our ML stack with the engine. Stuff I know very well, so I knew the "flow" but not the language tools to express it... so I wrote a lot of terrible stuff, learned more, and went over the code again the week after with better understanding. But I think you have a good point about the blogs. Learning Rust requires understanding three different things for me: how the safety rules work (sync, send, borrowck), how to best use the functional tooling (sum-types, pattern matching, expr-blocks, ...), and how to effectively write generic code (traits, bounds, lifetimes, and their high-order variants). The most flashy of these are the least useful. I use expr-blocks every day; but higher-order traits? Only for very low-level code. And that's before you even begin thinking about
async
, which is a whole separate beast in many ways. But knowing the first three will at least make understanding async's idiosyncracies a lot easier.
One thing that really helped me early on was trying to write code in different styles. Coming from C++ and Python I wrote a lot of really direct, imperative code. Pointers, boxes, lots of primitives and structs. One of my colleagues who I collaborated with was really into the functional/OCaml-lineage of Rust. Lots of sum-types, value-based workflows, pattern matching, etc. Just a whole different flow.
h
When I first learned Scala I wasted time trying to write "Java-like" code before fully coming around to embracing idiomatic Scala. I didn't want to fall into that trap with Rust, so reading the books, plus working in an existing, well-written codebase, was very helpful.