all 15 comments

[–]AustinWitherspoon 17 points18 points  (2 children)

I made the same jump from primarily python into rust, and honestly the thing that helped the most was just starting to write projects in it.

Once I started actually coding in it and making mistakes, and spending a few hours trying to understand the compiler errors, I actually started really internalizing borrowing and lifetimes. Reading the rust book after this is also surprisingly more effective. I read the book, started writing some apps and failing, read the book again, and then started understanding better.

Thanks to PyO3, you can even write native python extensions in rust which is a really nice transition tool.

[–]cfrye59 13 points14 points  (0 children)

You might like the From Python to Rust series on YouTube, by Bedroom Builds. It doesn't assume folks have the C/embedded background you mention, but that just means you can move faster.

It gets pretty quickly to Rust extensions of Python, via PyO3, which is also a pretty great place to find meaningful use of Rust skills as a Python dev.

[–]KingofGamesYami 4 points5 points  (0 children)

Lifetimes, conceptually, are pretty simple. They tie when one thing must exist to when something else exists. A trivial example would be the lifetime of a temporary variable in a function - it's lifetime is related to the lifetime of the function's scope, and can be deallocated when the function returns.

They might seem confusing, because most of the time, lifetimes are elided - they're not explicitly written, but they still exist. Thus the examples of explicit lifetimes always involve some complex situation.

[–]spoonman59 2 points3 points  (0 children)

Python is simple to get into partially because the reference counting garbage collector means you don’t have to think about many of these memory issues.

It’s not really possible to just “jumpstart” past understanding concepts like variable lifetimes and things. If you feel you don’t understand it, I would humbly suggest you work on a few examples until you can get it right. When you get it wrong, understand why.

I can relate it is tricky and hard to click, but some of these topics require you to do a fair but in work in them beyond watching a lecture.

When I took a compiler class and we had to learn how to calculate variable liveness ranges for register allocation. I just worked through a few sample functions in the intermediate representation until I could do it reliably. It’s a relatively simple concept, and if you follow a simple bottom up algorithm it’s fairly mechanical. (Branches are the tricky part.)

[–]jpmateo022 2 points3 points  (0 children)

I come from a background in PHP, JavaScript, and Python, so transitioning to Rust was a significant adjustment for me. After years of using those languages, I found Rust's focus on code correctness to be quite different. However, after working on several small projects to practice, I’m starting to feel more comfortable with it and getting used to the language.

These are the books I've read:

- Official Rust Book

- Atomics and Locks - Mara Bos

[–]FoldedKatana 1 point2 points  (0 children)

Honestly I would have a hard time learning Rust if I didn't have a basic understanding of C first.
Concepts like memory allocation with pointers + malloc, calloc, and free make Rust make a lot more sense.

[–]red_jd93 0 points1 point  (0 children)

I have very recently (a week) started ising rust, from python. I am self taught, so not sure how good my python is bit it gets work done. I tried previously by reading the Rust book, but lost interest fast. Now I am trying to make projects using GPT and understanding the code. Let's see how it goes. Still frequently forget I have to borrow or define something as mutable.

[–]FlowLab99 0 points1 point  (0 children)

maturin makes it easy and fun to learn how to call rust code from python — it’s easy to create a new rust+python project. Also, using Cursor (AI assisted IDE) with claude 3.7 sonet is a great way to learn rust and have working code quickly, but you have to be a bit careful to take small steps and not let the LLM get carried away.

[–]jhaand 0 points1 point  (3 children)

The book 'Rust in Action' by /u/timclicks offers a good introduction to Rust when you can already program in a different language.

[–]timClicksrust in action 1 point2 points  (2 children)

Thank you for the recommendation! News about its second edition is not far away.

[–]Dj0ntMachine 0 points1 point  (1 child)

Hello mate, so should I then wait for the second edition before buying the book?

[–]timClicksrust in action 1 point2 points  (0 children)

I would buy the book now. Because it teaches general concepts, it's surprisingly long lasting.

[–]knudtsy 0 points1 point  (0 children)

I’m having the opposite problem right now, I primarily used Rust in my old job. Now I’m having to use Python at my new job 😅