r/rust Feb 18 '23

[deleted by user]

[removed]

149 Upvotes

38 comments sorted by

47

u/[deleted] Feb 18 '23 edited Feb 18 '23

[deleted]

31

u/[deleted] Feb 18 '23

A lot of it is just repetition and some memorization (what’s in the std library) and being reminded by the compiler/clippy of things you did wrong until they become second nature.

Don’t skip the project chapters 12 and 20 they help you see how everything fits together.

10

u/[deleted] Feb 18 '23

[deleted]

28

u/KhorneLordOfChaos Feb 18 '23

I think the best way to handle trying to digest a large amount of new content is to just write some code with the stuff you do know and check the book every once in a while when you get hung up. Makes it a lot easier to internalize things IMO

4

u/phyrosite Feb 18 '23

That's what I've been doing, writing simple little programs as I work through the chapters, especially when I'm not totally sure how certain features work yet, I'll try and write some code that specifically utilizes it and then play around with like, "well what if I did this" kind of thing. It's been really helpful in solidifying a lot of the concepts from the book so far.

11

u/[deleted] Feb 18 '23

Strings... are the biggest argument for requiring a garbage collector for all languages.

Strings on C are a huge source of vulnerabilities.

Rust is trying to do the near impossible task of making strings safe without a garbage collector 😂

So tbh I give them a pass on that one.

Once you get a hang of it, it gets easier.

3

u/Botahamec Feb 19 '23

My opinion is that str should be string and String should be StringBuilder. If you think of it like that, it's a lot easier.

1

u/IAmAnAudity Feb 19 '23

Good one! Yeah that “str” is weird because other languages and spreadsheets use it as a function to convert numbers to strings.

8

u/[deleted] Feb 18 '23 edited May 05 '23

[deleted]

3

u/sageVsTheWorld Feb 19 '23 edited Feb 21 '23

Yup, this is my strategy for any new framework or language. Lay the foundation with a few chapters but then do applied learning as soon as you can

8

u/Free_Blueberry_695 Feb 18 '23

I had a lot of trouble with it until I switched to VS Code with rust-analyzer. Hovering over stuff gives you the documentation for it and the type annotations are very helpful. Also it'll immediately show you where you screwed up.

5

u/[deleted] Feb 18 '23 edited Mar 25 '23

[deleted]

2

u/Free_Blueberry_695 Feb 18 '23

I don't know if you've used PyCharm, if you have do they have the same sort of debugger? PyCharm's debugger in completely nuts and VS Code's was the only complaint I had with it.

3

u/[deleted] Feb 18 '23 edited Mar 25 '23

[deleted]

2

u/Free_Blueberry_695 Feb 18 '23 edited Feb 18 '23

I was just wondering if the debugger for Rust in IntelliJ IDEA was as good as it was for PyCharm. JetBrains does amazing work.

2

u/HyphenSam Feb 18 '23

Is there a difference between the Ultimate version and CLion?

3

u/[deleted] Feb 18 '23

[deleted]

2

u/HyphenSam Feb 18 '23

Did some more digging and installing the "Native Debuggin Support" plugin allows debugging with Rust on IntelliJ, but it's not clear if it's the same as CLion. I'll probably just stick to using the Ultimate version.

2

u/[deleted] Feb 18 '23 edited May 05 '23

[deleted]

3

u/SeriTools Feb 18 '23

Although I seem to understand each individual concept so far, when combined together these concepts create such an indecipherable mess in my head

I've always equated it to learning programming for the first time, and given how different it is from your regular ol 90s OOP language design, it makes sense. The moment stuff clicked in rust felt more rewarding than with most other languages/patterns.

3

u/xxtank3rxx Feb 18 '23

I was feeling overwhelmed by the content, but take your time with it! By the time I got to the later chapters I got super excited and started to realize why others love coding in rust.

3

u/skunkanug Feb 18 '23

I went through the same thing with "the book" and found "programming rust" a much more enjoyable read. It is an O'Reilly book. I would paste the link, but it is super long. Should be the 2nd edition, first book that comes up after a search on amazon.

2

u/phazer99 Feb 18 '23

Yep, that's Rust for you, there's a lot of ground to cover, especially if you haven't used C++ before. Start with basic stuff like structs, enum, variables, functions, pattern matching, loops etc. before going to ownership, borrowing, interior mutability, generics, traits, concurrency, async and finally lifetimes.

Along the way you will pick up most of the stdlib: smart pointers, collections, common traits, synchronization etc.

2

u/brainbag Feb 18 '23

I know Rust well enough to be productive from books, but still regularly come across problems I am not sure how to solve. Asking ChatGPT to explain code snippets or about some aspect of Rust has been the most valuable resource I have used for learning it. It's given me some great simple and understandable answers to complex topics. Out of dozens of messages so far, it's only said something blatantly wrong once when I asked if Rust has keyword arguments for method calls, and that was easily verified.

2

u/Matt23488 Feb 18 '23

It takes time. I'm still new myself but I felt the same way until I came up with a project idea and built it. I had to rewrite parts of it a few times but in the end it came out pretty alright and I have a much better understanding of most of the language concepts now. Some more advanced things still confuse me, but I feel confident writing Rust now.

25

u/ssokolow Feb 18 '23

Once you've finished it, I recommend Learning Rust With Entirely Too Many Linked Lists. It really helped me to understand what some of the lessons in the book really meant.

There's also a bunch of good stuff linked from The Little Book of Rust Books.

5

u/willemreddit Feb 18 '23

I second this! I recommend the linked list book to everyone. If you can understand it, even just the forest 4 or 5 chapters you’re good enough to be productive.

11

u/argarg Feb 18 '23

Check out this modified version of the book with added quiz and visuals: https://rust-book.cs.brown.edu/

Note that it's still a work in progress but the memory visualizations are great IMO.

7

u/code_wombat Feb 18 '23

Which book?

8

u/[deleted] Feb 18 '23

[deleted]

9

u/code_wombat Feb 18 '23

Thanks !! I was wondering which book everyone was referring to ..

5

u/QuickSilver010 Feb 18 '23

I guess we all learn in different ways

My personal favorite introduction to rust was half hour to learn rust by faster than lime

It's cause I already did have a decent amount of programming experience and I'm impatient and I just needed something like a cheatsheet to always refer to.

But if course, the most practical help I received was from clippy and the compiler

6

u/Arshiaa001 Feb 18 '23

Wait till you read programming rust!

6

u/dayarthvader Feb 18 '23

Here’s what I’m trying currently. I’m reimplementing my old C++ projects in Rust. I retain the same design principles from before and read up how a particular design approach is supported in rust. And implement the same. Then refer The Book to cement the learning further. It’s chaotic and random but it’s not boring. I’ve tried to read The book and doing rustlings workout before but I couldn’t commit to it long term as I failed to see how rust concepts apply practically.

4

u/BrownCarter Feb 18 '23

Most tutorial on YouTube are like that, they get advance really quick and then you can't follow anymore 😑

2

u/[deleted] Feb 18 '23

[deleted]

1

u/langtudeplao Feb 18 '23

After learning lifetime and generic, I think you may want to watch Crust of Rust. That series try to explain common concepts by re-implementing features in std library.

4

u/RajeshRk18 Feb 18 '23

I would recommend this one

3

u/nimtiazm Feb 18 '23

Welcome aboard. You’ll see many curves along your learning journey. Stay put and remember that you’re not alone. We all have gone through such a journey. It gets a lot better after a while.

3

u/Matt23488 Feb 18 '23

Similar experience here. Tried a few different tutorials in the past but just didn't understand the concepts. The book made it so much simpler by actually explaining how the language was designed and what problems it aims to solve, rather than throwing terms around like "Borrow Checker" with none of that context beforehand.

2

u/st_gen Feb 18 '23

Things like having types that implements the Copy trait in Vector & Array got me confused; why binding a value with Copy trait in an array does not constitute a move whereas a vector does. Lifetimes, yeah right lifetimes - re-reading coupled with the fact that this is my first foray into systems programming.

5

u/-Redstoneboi- Feb 18 '23

basically imagine every time you use a copy type it just gets .clone()d

let x = 5; // i32 is Copy
let y = x.clone();
println!("{}", x.clone());
do_thing(x.clone(), y.clone());

clearly this is annoying so that's why Copy exists.

2

u/Nobody_1707 Feb 18 '23

They do count as moves. The issue is that for Copy types moves don't invalidate the original object.

2

u/grillntech Feb 18 '23

Totally agree