142
How to learn Rust? (lemmy.world)
submitted 3 months ago* (last edited 3 months ago) by MoonlightFox@lemmy.world to c/programming@programming.dev

I want to learn Rust. There are so many resources available and I am unsure which one to go for, and if there are any tips on getting started?

I am a software developer by trade

Edit: Thanks for all the great replies!

top 35 comments
sorted by: hot top controversial new old
[-] StrikeForceZero@programming.dev 79 points 3 months ago

As a wise person once told the Internet, don't worry about picking the best one. But if you really had to pick one just start with the rust book. https://doc.rust-lang.org/book/ I would suggest to just dive in with a specific need you want to solve and instead of using your language of choice just use rust and look up stuff as you go. Hands on learning is usually the best learning. The only thing you need to "learn" is how to follow the ownership/borrowing paradigm that rust brings to the table.

[-] solrize@lemmy.world 17 points 3 months ago

I'm looking at this book now and I guess I'll keep reading, but the early parts are quite verbose and I keep waiting to get to a description of the language. Something like "Rust for C++ programmers" might be worth a shot: https://github.com/nrc/r4cppp

There are a few different things like that for Ada. There are also a few "Rust for Haskell programmers" and I might look at a few of those.

[-] SkavarSharraddas@gehirneimer.de 18 points 3 months ago

There's also Rust for the Polyglot Programmer which seems to be a generic version of those.

[-] solrize@lemmy.world 3 points 3 months ago

Thanks this looks good.

[-] Digital_man@lemmy.one 30 points 3 months ago
[-] catalyst@lemmy.world 12 points 3 months ago

I second rustlings, it’s really good!

[-] gbin@lemmy.ca 2 points 3 months ago

Was about to say this one, it is very good!

[-] snaggen@programming.dev 23 points 3 months ago

https://doc.rust-lang.org/book/ this is a great starting point. Then when you got the basics, and fiddled around a bit, then you can start looking for more specialized books (like Rust Atomics and Locks https://marabos.nl/atomics/ )

[-] Solemarc@lemmy.world 18 points 3 months ago

IMO the best way to start in a new language is to rewrite some of your previous projects in that language.

I generally start out by rewriting a couple simple 1-3 function console apps, basic leet code stuff like; palindrome, fizzbuzz, reverse an array in place, etc, and some simple unit tests for them. Then I go ahead and rewrite some of my previous projects or uni assignments in that language.

At that point I generally have a good understanding of basics and have an idea of how to approach a new project. When I got to this point in rust I then started on threading, async, why it's easy to return a String and an ordeal to return &str, etc.

[-] hector@sh.itjust.works -1 points 3 months ago

Please, don’t ever use async Rust lol :( it’s so terrible to work with closure recapture. There’s really one way of structuring your code to keep the borrow checker happy and I haven’t yet found it in my projects lol.

[-] FizzyOrange@programming.dev 6 points 3 months ago

Yeah I would also recommend avoiding async Rust as much as possible. There's really only a small number of situations where you need it - WASM, embedded (Embassy), and unfortunately most of the web ecosystem forces you to use it even if it isn't necessary for 99% of people.

Sync Rust - even multithreaded - is absolutely fantastic at protecting you from mistakes & giving an "if it compiles it works" experience. Async Rust on the other hand is full of surprising and difficult to debug footguns.

[-] stringere@sh.itjust.works 15 points 3 months ago
  1. Combine iron with moist air.
  2. Wait.
[-] LowtierComputer@lemmy.world 6 points 3 months ago* (last edited 3 months ago)

Let's not waste time! Add salt.

[-] ITGuyLevi@programming.dev 2 points 3 months ago

Save a little more and add some hydrogen peroxide!

[-] LowtierComputer@lemmy.world 1 points 3 months ago

Nitric acid!!

[-] otter@lemmy.ca 13 points 3 months ago* (last edited 3 months ago)
[-] maegul@lemmy.ml 13 points 3 months ago

Cheers for the shout out! Yea the idea of that community is to be a kind of study group.

Whenever I've posted a thought or idea, that's part question part experiment part pondering, I've gotten great replies from others.

Also two people have been running twitch streams of running through the book. Sorrybook is nearly done I think (they've been going for half a year now which is quite impressive).

The community is at a point now I suspect where some of us have learnt rust well enough to spread out into projects etc, so it'd be nice to work out how we can do that together at all.

Part of my initial idea with the community was to then have a study group for working through the lemmy codebase, treating it as a helpfully relevant learning opportunity ... as we're all using it, we all probably have features we'd like to add, and the devs and users of it are all right here for feedback.

Additionally, an idea I've been mulling over, one which I'd be interested in feedback on ... is running further "learning rust" sessions where some of us, including those of us who've just "learned" it, actually try to help teach it to new comers.

Having a foundation of material such as "The Book" would make a lot of sense. Where "local teachers" could contribute I think is in posting their own thoughts and perspectives on what is important to take away, what additional ideas, structures or broader connections are worth remembering, and even coming up with little exercises that "learners" could go through and then get feedback on from the "teachers".

[-] Benjaben@lemmy.world 3 points 3 months ago

Welp, YOU'RE frickin cool, kudos!

[-] maegul@lemmy.ml 6 points 3 months ago

Cheers! Actually not sure exactly why you're saying this (I'll take the good vibes though) ... but if you're keen to join in in any way you are most welcome!

[-] Benjaben@lemmy.world 5 points 3 months ago

I was simply pleased by your comment, to see how much you care about helping folks and moving the community forward. Seems like quite a lot of effort to me, far more than I'd be able (willing?) to contribute, and I'm just forever grateful for folks you like you and wanted to say something about it :)

I appreciate the invite. I'm not at a point currently where I can put sincere effort toward much that's non-essential, but if that changes, Rust is on my short list of targets for ways to spend some spare effort and time.

[-] maegul@lemmy.ml 4 points 3 months ago

Cheers! Very much appreciate the love!

[-] thefatfrog@lemmy.world 10 points 3 months ago

If you are looking to create a web service, I can suggest the zero2prod book. That’s how I learned rust and loved the process. I was also already a seasoned developer before taking interest into rust

[-] InternetCitizen2@lemmy.world 9 points 3 months ago

A big part is kinda just doing it. I am trying to learn and it is kinda wild. I am currently working a warehouse job so it is hard to find the time. Try and go back and implement some of your favorite homework assignments in Rust.

I think a hard part of Rust is the mind shift. It just feels very different from anything else I have tired. I am doing some encapsulation for my learning, but it is not clear where to read about it and there are few examples out there.

[-] unquietwiki@programming.dev 9 points 3 months ago

I just found https://google.github.io/comprehensive-rust/ today. Structured course developed by Google for its Android devs.

[-] tiredofsametab@fedia.io 8 points 3 months ago

I agree with the others who say to start with The Book -- https://doc.rust-lang.org/book/

From there, start trying to create small things that you might want or need to do (parsing JSON is something that I needed to do and I started there).

From there, you will learn to fight the borrow checker and start to feel how rust is working. This will be annoying at first, but get better over time (at least in older versions of Rust; I haven't used it in a while so it may be different now).

[-] nephs@lemmygrad.ml 1 points 3 months ago

Read the official rust book until you feel like want to experiment with something, then go to advent of code and try something, anything out.

Then start investigating why it doesn't quite work. And I guess gpt for suggestions and random questions isn't a bad idea.

[-] Iapar@feddit.org 0 points 3 months ago

What is the borrow checker and why are people so frustrated by it?

[-] tiredofsametab@fedia.io 3 points 3 months ago

Very TL;DR version: a variable has an owner. If you pass it off to another function, you no longer own it and can't use it until/unless it gives the variable back. Rust can be really strict on making sure you aren't trying to use something you don't own at that time. The documentation explains it better than this (and I wrote a longer post but accidentally closed the window and lost it). See also mutability and lifetimes for some pain points people might not be used to.

[-] Iapar@feddit.org 2 points 3 months ago

Thanks for the answer!

[-] rezz@lemmy.world 7 points 3 months ago
[-] haskman@programming.dev 5 points 3 months ago

Others have listed a bunch of good resources. If you are more of a visual learner, I have heard good things about the Easy Rust videos - https://www.youtube.com/watch?v=-lYeJeQ11OI&list=PLfllocyHVgsRwLkTAhG0E-2QxCf-ozBkk

[-] Hawk@lemmynsfw.com 4 points 3 months ago

The book is really good and offers a snapshot of those inner workings of the language.

For using it, LLMs (open weight and otherwise) perform very well and may fill the gap.

[-] DumbAceDragon@sh.itjust.works 3 points 3 months ago

People already suggested it, but rustlings is awesome.

One thing I like to do is think of something I often do in another language, then Google how to do it in rust, i.e. dynamic dispatch. The way rust does it with traits is really interesting.

[-] GetOffMyLan@programming.dev 2 points 3 months ago

I started with the rust book and used chatgpt for any follow up questions I had.

[-] Randomgal@lemmy.ca 1 points 3 months ago

Just hop on a public server and try to make some friends. If you join right after a wipe there will be lots of nakeds on the beach looking for fun.

this post was submitted on 26 Aug 2024
142 points (98.0% liked)

Programming

17314 readers
302 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 2 years ago
MODERATORS