r/learnrust • u/warlock7867 • 29d ago
Biting the bullet and learning rust
I'm finally going to learn rust. My entire professional career I've used Go and some Python scripting. Even my personal projects are written in Go. I decided the best way for me to learn Rust is by translating one of my older projects from Go to Rust. Turns out it's not that simple. There are quirks in Rust that I don't understand (like lifetimes and memory management) and some quirks of Go that Rust is very opinionated about like enums.
I tried converting my chess engine in Go to Rust and ran into quite a bit of challenges that led me conclude that I need to pick up something less complex and learn the language on its own terms. So any advice on that front would be very helpful. I have already downloaded the The Rust Programing Language Book and watched a couple of videos on YT. But I'm a practical learner. I need to build something to really learn this language.
4
u/Any-Roll-2272 28d ago edited 28d ago
Rust is great when project gets larger and larger. It’s much easier to find a system bug or harder to create a one. Compiler feedback’s are precious.
Basically, rust doesn’t have garbage collector like go, it has rules how to make safe code. Ownership check, borrow checker, lifetimes… Once u wrap your head around it, it’s easier. Also use AI to learn it, on end rust and ai plays well together due to compilers feedback. Lifetimes was hardest for me… in most cases rust knows when to free memory, in some you need to mark lifetime.
Regarding lifetimes and memory management to grasp the surface watch 35 min of videos to get in touch with it’s concepts:
https://youtube.com/playlist?list=PLSU4tMo3A8YE&si=O1Pion6VudQLP8w_
To understand more why there are challenges with memory management and why is Rust so good, check Harvard’s CS50x memory lecture: https://youtu.be/db0H0U13YsA?is=5JwkTHUZOK5REDFk
You said that you are practical learner, then in parallel from official web page skip the book and do: by example and rustlings course. https://rust-lang.org/learn/
After rust DX, there is no going back ;)
p.s. rust has mini, micro, nano garbage collectors only when u call them. They assign memory on heap and drop /free it automatically.
1
1
7
u/tjk1229 28d ago edited 28d ago
A lot of languages allow patterns that do not work with memory ownership and lifetimes. This is how rust gets its type safe guarantees.
Your code architecture will have to change to take full advantage of its features and safety. As tempting as it is, do not just go straight to box, arc, arc mutex or something like that.
Best way imo is write something in rust you are familiar with. Start small work up. If you run into an issue start looking for resources on that issue. Maybe a data structure or pattern etc that solves the issue
1
u/hedgpeth 28d ago
It took me about 3 months to really get ownership, and 6 months to find a groove and 12 months to remap my whole brain to it all, working full time on it. And this was pre-LLM, so I'd work through how to get yourself engaged in that way over time, and have patience, hope that helps!
2
u/warlock7867 28d ago
I get what you mean. The philosophy of Rust is quite different from that of Go. I inadvertently end up writing code that looks like Go and I KNOW there is a better way to write it to fully utilize Rust. I need some sort of a roadmap, you know?
1
u/kewlness 28d ago
I know AI gets a lot of hate for various reasons, but I wouldn't stop converting your chess engine from Go to Rust. I would use AI as a senior Rust developer or a rubber duck to bounce ideas off of and to explain complicated subjects. AI doesn't have to write any of the code - everything should be written by you. But having that explanation goes a long way to understanding and you will continue to understand by doing.
Good luck!
1
u/warlock7867 28d ago
I understand AI gets a lot of hate and 95% of the time it’s just justified in my opinion. I’ve been slow to integrate AI in my personal projects because it’s defeats the purpose of those projects. Nothing personal if it’s done using an LLM. But you make a good case for its use in this scenario. And like a lot of other people said, I need to get basics right in Rust.
1
u/old-and-very-bald 22d ago
Rust is tough at first, but with time things start to make sense! I built a small browser game to make learning more interactive (I find it hard to learn just by reading books), maybe it helps you find your way to Rust! https://reinhash.com/demos/be-the-borrow-checker/
1
3
u/jimmiebfulton 28d ago
At first, it will feel like a very steep, punishing learning curve. But at some point, it will all start to snap, and you'll be asking yourself, "Why did I think that was so hard?" And then, you'll be an even better engineer for it. It changes the way you design and build software.
1
2
u/karasawa_jp 28d ago
Using traits in Rust requires an understanding of lifetimes and generics, so writing in an object-oriented programming style in Rust is very difficult. If you feel that frustrating, I recommend translating interfaces in Go to enums in Rust. That's much easier.
2
u/CelebrityChess 28d ago
Since you already have the Rust Book, I’d use it as the roadmap: work through ownership and borrowing, then structs/enums and pattern matching, then Result and error handling, doing the matching Rustlings exercises as you go. Build a tiny CLI or board-state toy first rather than porting the whole chess engine. For each borrow-checker error, trace who owns the value and whether the caller needs a shared or mutable borrow before adding Box or Arc. That keeps lifetimes and enum design concrete.
1
u/tvl2386 28d ago
I've done ruby on rails for almost 20 years. I'm a network engineer and love to automate everything away. I wrote a couple of Go apis with huma and it is awesome. I also took up rust recently and did rustlings to learn it. It was awesome. It gradually introduces you to all the rust concepts. I can highly recommend it. I made my first rust webapp using loco with SQLite. It was really enjoyable and I love rust for the performance and the rigidity of everything if that makes sense. Don't get me wrong, I'm still a rust noob
1
u/hrubydavid 28d ago
I am doing 1BRC by following Jon Gjengset's 10.5-hour YT stream to learn Rust by practice. It’s full of amazing problems. I am chatting about the progress here too: https://www.reddit.com/r/learnrust/s/R9oWipmGkD If you feel you would enjoy it too we can chat about it. You know more people more fun.
I’ve been mainly java/scala developer in past ~20 years but now I am trying to switch to Rust. I love the language and the community looks amazing too. Smart people with nearly no evil.
Many people said that understanding Rust makes you better engineer (even here somebody said that) and I have same feeling. Every day with Rust makes me better. I feel it a lot. But I don’t want to just use Rust. I want to understand it. Saying that I know people who use Rust through AI agent and it’s not same to me (not saying AI agentic programming is wrong as it has a usecase).
So thank you for your post too as it was helpful to me me as well 👍
1
u/First_Ad_2000 28d ago
Start by translating a simple CLI tool like a todo list that only uses vectors and structs. Ignore lifetimes for now because you can put everything in the same scope so the borrow checker stays happy. This isolates the syntax differences without fighting ownership rules immediately.
1
u/Immotommi 27d ago
One thing you could do is convert your chess engine to rust incrementally. One very useful skill with rust is being able to mix it with other languages.
So rewrite a section in rust, call it from Go.
(Don't know the details of your engine, and not intimately familiar with engines) But maybe you start by writing the code that does tree search in rust. Or the code that parses positions. Pick self contained sections which have well defined inputs and outputs
21
u/bobthemunk 28d ago
Maybe try Advent of Code for concrete problems to solve to get comfortable with the language constructs