Hacker News new | past | comments | ask | show | jobs | submit login
Learning Rust in 2020 (github.com)
146 points by yannikyeo 12 days ago | hide | past | web | favorite | 37 comments





> When I started learning Rust I made the mistake of following the advice to read The Book first. While it's a great resource, it's pretty overwhelming for a beginner to get told "If you'd like to learn this programming language the best way to start is to read this 20 chapter book!" Most people give up before they even get started when they get advice like this. Nobody ever told someone to read a 20 chapter book just to get started with Javascript or Python. Rust's learning curve is no joke but you gotta give the people what they want, and they want to program, not read about programming. Programming is fun and reading about programming is not as fun.

As one of the authors of the book, I wholeheartedly agree that it's not for everyone. Folks should learn in the way that works well for them. I'm glad this resource exists!


I don't usually like programming books. I am usually easily overwhelmed by them and I find that they are at the wrong pace for me.

This weekend I read most of the Rust book without much effort and found it really helpful for getting up to speed with the language, especially the more novel bits around safety. It took me to the point where I was able to explore and evaluate the bits of the language I needed with only library docs. I know that the remaining chapters are there for when I am ready for them.

My experience with the Rust book as made me more likely to consider starting with a book when approaching programming languages in the future.

Reading other comments, I recognize that I was fortunate to have a project in mind that motivated my reading of the book and just happened to be an excellent fit for Rust.


As someone who already programs in multiple high-level languages, I feel that the Rust book hits the sweet spot for me. It doesn't go over basic programming concepts which I already know, and focuses on fundamental, unique concepts of Rust. I feel that the scope is pretty close to perfect as well, it doesn't try to cover every single detail. (The Rustonomicon serves as Part 2 for me)

I'm in the same boat. I worked on a pet project while reading the book (still at it). Make some progress, read about how unit tests are done, add some unit tests, learn how modules work, refactor some code into a module.. Inbetween I google some things that I need but haven't mentioned in the book yet but that I need at that moment (e.g. cow strings used in a crate). Works for me!

Thanks for the kind words!

Came here to say this exact thing. I never learn well from programming books, but I did from the Rust book. I think it's because of how bite-sized and focused the different pieces are, as well as how hands-on and example-driven it is.

To be fair, when I first saw this advice to read the book first, the book was this one: https://doc.rust-lang.org/1.30.0/book/first-edition/ which is much shorter.

That is, the advice "the best way to learn Rust is to read the book" came from when the book was a different one; it's still repeated (perhaps by people who learned from the old book), but it might no longer be as valid.

Just for fun, I've been re-reading the book (that is: reading the new book), and it's much more tiring than I remember the old book being (but I've learned a new trick or two, things that didn't exist back in the Rust 1.0 days when I first learned through reading the book).


Yeah. I think it comes down to style. The new book is almost exactly twice as long as the old one; the old one had less stuff to explain, and also didn't explain it in as much depth. Some people prefer brevity. Some prefer the extra explanation. It's a constant struggle to keep the book from getting even longer.

I think the new book is far, far, far better, but I can understand why some other folks don't agree.


I think personally I like it when things go in "layers". Start with a shallow pass, and then do one or more passes of increasing depth

Yes I think that line highlights the "different strokes for different folks" aspect of learning things: my instinct when I learned javascript and python was to pick up and read long books about them! I'm glad there are lots of different kinds of resources that exist, which people can pick and choose from as best suits them.

I've read the book and its iterations 3 times. It may not be for everyone but it's been wonderful for me. When I was first learning Rust some time ago you were also a great resource on IRC. Thank you Steve.

<3

I'm about 1/4 of the way through your book, and it is my favorite programming book since the original C book, which I read ... sigh ... almost 30 years ago.

Well done!


If it makes you feel any better, I also read that book... 20 years ago? Regardless, thanks!

> As one of the authors of the book, I wholeheartedly agree that it's not for everyone. Folks should learn in the way that works well for them. I'm glad this resource exists!

I started off reading your book, and I found it really helpful, even though I didn't make it all the way through. I feel like there are a lot of resources cropping up that are good supplemental material (the "half hour to learn Rust" blog post linked in this document being one of those) which can quickly get people up to speed, but the details in the book are still valuable.

Reading through (most of) the book was really helpful when I went to Exercism (another fine resource recommended by the post linked here), and I still use it as a reference when I am fuzzy on a concept.


I did like to book. I read it in small steps over like 3 weeks. The only thing that's really missing and makes people get a rough start is, that there is no step-by-step dev environment setup. VS Code + Rust (apparently what most people use) should work "out of the box" but nowhere is an official and maintained recourse how to set it up correctly. Just a bunch of outdated blog posts how someone someday got it to work. If you never used VS Code before you are almost certainly waiting hours to get you rust scratchpad running which you definitely want to have while reading the book.

Yes, is may not really fit in the book but then there should be a official place for this. Preferably with different OSes and IDEs covered.


The book should mention that one should use rust-analyzer rather than RLS as the code completion engine in VSCode. The former is much better.

This is part of why doing this is tricky, and why we don't. If this section were in the book today, it would say the RLS, because the RLS is the current project from the Rust Project proper. That's about to change, but still, it's a good example of why this is hard.

It should ofc name both and give all the information needed for a beginner to make a educated decision what to use.

But like I said the book may not be the right place for this but there MUST be a place for this and if not then such a place must be created. Many many other languages/frameworks etc. have the same problem.


The rust book is great and I refer to it frequently, but rust never clicked for me until I just jumped in and did the advent of code with it.

I think the hard part of just reading the book is that unless you have some problem you’re trying to solve, it’s hard to get motivated to read it.

It’d be nice if there was a book that’s a bit less dry —- something like Learn You A Haskell or Why’s poignant guide to Ruby.


I would also love to see a book with some whimsy; when I try to emulate this style, it doesn't work. Oh well.

Currently on day 4 of reading it all day and just finished chapter 12.

Thanks for writing it!


I wish every language had the equivalent of https://tour.golang.org.

Edit: hey thanks to both answers, bookmarking it for later. I'm learning Haskell right now and it definitely misses something like this.


Our version of this is https://doc.rust-lang.org/stable/rust-by-example/; though someone recently tried to start a more direct port!

If you're looking for an equivalent for Rust, I've found Rust by Example[1] to be an excellent resource.

[1]: https://doc.rust-lang.org/rust-by-example/


A Rustacean recently started https://tourofrust.com/ as the Rust-version of the Tour of Go! It's still WIP but looks pretty great so far.

Re: Haskell, not quite as practical as the Go tour but I think the learning curve is similar: http://learnyouahaskell.com/chapters

Nice!

I just started learning Rust for a WebAssembly project.

The people on the Discord server are nice and quick to answer questions.

The ebooks I found online are a bit hard to grasp. At least for a JS dev like me.

I mean, for the basics they're okay, but what I'm missing is how to write "good Rust code". There are always multiple ways to do things (Option/Result, try!/?/unwrap/expect, loops/map/fold, etc.) and I already produced some runtime errors, haha


I'm not sure how the broader community does it, but the Rust developers that I know (myself included) will typically get the code working and compiling with panics and unwraps (especially when working with a new API or just experimenting) and then do a second pass to "remove panics". This typically involved reviewing your code thoroughly, finding each panic / unwrap / expect, and using this to identify how your functions can fail. This is a good time to create error types for your API and note these cases in your documentation. You then convert functions which can fail to a Result and all of the unwraps etc. to ?. This can be fairly mechanical and really gives insight into ways that your code can fail and edge cases, but does take time.

As far as loops vs maps, I've found that your use case typically guides this. I think this is the same with other languages like Python. You aren't going to want to write a ton of complex logic in deeply nested maps and filters. But if you just need to do something more simple it might make more sense to do it in a map one-liner.

Edit: The presentation linked to in the other reply appears to confirm this process of starting with dirty compiling code and then refactoring out the possible failure modes. It covers a lot more things like using match and handling errors from other libraries.


In the beginning, I find it is best to avoid the escape hatches that lead to the runtime errors I assume you're talking about (i.e., `unwraps` and such). Eventually you'll learn when it's appropriate to use them.

https://github.com/mre/idiomatic-rust https://speakerdeck.com/mre/idiomatic-rust-writing-concise-a... < fun basic idiom examples (don't necessarily take the use of the failure crate as idiomatic, but the rest of the methodology seems to be)


Mate, in opposition to the article I'd say read the book! What you're talking about is trying to get a deeper understanding.

I've been working through the Rustlings exercises for the past week or two. I get through a handful at a time (spending 20 min to an hour) and have done maybe 5 or 6 sessions. It doesn't seem short to me (doesn't seem long either, but it isn't like I blew through it in a few hours). It can be confusing as the hints are sometimes really vague. I've cobbled my way through so far and if I've gotten stuck I just stop and come back to it another day. Usually I can progress quickly with fresh resolve. It is nice in that it helps you learn the syntax, but it doesn't seem to help me much with the concepts. I feel this is in part that when you run `rustlings watch` it doesn't first point you to the section of the book you're reading it just throws broken code at you and tells you to run `rustlings hint <foo>` which only sometimes points to the book. Most of the time you are just given broken code and asked to fix it with some suggestions of where to look in this specific code. I have completed 53 exercises and am in the process of working on standard library types. I could go into some more specific details if anyone is curious about my experience. Hoping to post my annotated work through to github when done, but I could either copy out the few bits that were particularly vexing or could post the code with my comments now for people to peruse. One thing I would like to find is a place to start interacting and asking questions. Heard someone mention discord so I'll maybe start there or on IRC.

Hi, author here. Rustlings took me only a few hours but I came back to it after I had already finished reading The Book and finished about ~100 exercises between LeetCode and Exercism, so my experience with Rustlings wasn't that of a "true newbie". I still think it's one of the best resources out there, but like anything it can continually improve.

Your feedback as a beginner is very valuable! If you have some structured feedback for Rustlings please consider opening an issue on the repo. Also, the official Rust Discord Server is very beginner-friendly and has a #beginners channel, if you're struggling with anything don't be afraid to join and ask your question. The invite for the server is here https://discord.com/invite/rust-lang


Im kind of dismayed that we're told that reading about programming isn't fun. Also we're told what people like and what they don't. Is this what "people" like and don't like or what the author likes and doesn't like?

Learning the hard concepts in rust is exactly where the value lay for me. For some people I guess copying things and getting results without understanding is rewarding and I'd never say people shouldn't do that but author should not be telling people not to read. It's terrible advise.


Hi, author here. I enjoy reading about programming and I think it's fun, just not _as fun_ as programming. I tried to choose my words carefully because I didn't want to come across like I was bashing reading. Perhaps I should have said, "reading about programming is fun but programming is even more fun."

Learning the hard concepts in Rust is the best part, but The Book isn't going to teach you those. The Book, by design, is a very broad but shallow overview of the entire language. It'll never teach you, for example, why you can't write a self-referential struct in Rust. That's a lesson every Rustacean has to learn the hard way: by programming in Rust. And that's what I hope to encourage more Rust beginners to do: learn the hard lessons by actively programming in Rust.


I get where you're coming here, maybe the concepts in the book weren't difficult for you, but they were for me. I tried Rust without the book and got disillusioned so quickly as I didn't have the vocabulary to understand the docs or a lot of discussion (stack overflow etc) i bought the book and it openened up so much understanding for me and now I have a couple of Rust projects on the go.

I guess it upset me a bit because I didn't find Rust fun at all until I had the book and I could see how your piece could discourage people from buying it.


+1 for rustlings, it's fantastic, I went through it right after reading through the book. The books are good, but it's hard to compete with being hands on like rustlings is.



Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: