top | item 16594547

Learning Rust

229 points| dumindunuwan | 8 years ago |learning-rust.github.io | reply

69 comments

order
[+] mswift42|8 years ago|reply
Exercises, I want Exercises, no I need Exercises.

In order for me to learn anything, I need some form of "homework". If you want to teach me a new language, a new framework, I need to "get my hands dirty".

Working through exercises makes sure I actually understand what I am reading, and sometimes it even shows me I don't understand what I thought I did.

[+] jordigh|8 years ago|reply
How about Advent of Code? They start out easy, but after a while the difficulty is all over the place, and it'll force you to seek out new features of the language. It's a somewhat "realistic" way to learn the language, instead of having a set of more contrived set of exercises that only make you look at a particular part of the language.

The first day, for example, will kind of force you to figure out how to parse arguments, how to loop, how to convert strings into ASCII... all basic, practical tools that you will need sooner or later anyway. Now it's your job to pick up a Rust reference, look around for the tools that you need, and use them to solve an actual problem.

That's how I got very comfortable with D.

http://jordi.inversethought.com/blog/advent-of-d/

If you do this for Rust, I'd love to see a blog post like the above.

[+] mattherman|8 years ago|reply
You could take a look at exercism.io. I just started the exercises on there yesterday so I don't have an informed opinion on whether they are good or not overall, but it might be what you're looking for.

http://exercism.io/languages/rust/about

[+] YuukiRey|8 years ago|reply
I wholeheartedly agree with this! I am a pretty inexperienced self-taught frontend developer currently trying to learn Haskell and C. I went through Learn You A Haskell and have started going through Zed Shaw's Learn C The Hard Way.

On the surface, LYAH looks a lot more polished. It has nice drawings, less typos, seems like an actual book rather than a gathering of notes and thoughts turned into teaching material. But the exercises in LCTHW are amazing. They always challenge my knowledge in a way that often makes me realize that I didn't understand anything from the prior paragraph.

In LYAH I usually tried following along in GHCI to get an intuitive idea of the functions and patterns used. Yet, whenever I sit down to just build something that, while using the same features, deviates from the example code quite a lot, I often notice glaring holes in my understanding of the topics.

And so, bottom line, I want teaching material to ask hard questions which challenge my assumptions and perceived understanding. As a beginner, I can't come up with such questions on my own. Just presenting me with already assembled programs and going through them line by line just doesn't work (for me at least).

[+] bschwindHN|8 years ago|reply
While this probably isn't helpful to you in particular, my company has a learning site geared towards beginner/intermediate programmers, including some content on Rust. The catch: it's in Japanese, so you'll have to use Google translate if you can't read it. The code is in English though.

https://codeprep.jp/books?tags=&sortBy=createdAt&keyword=Rus...

The exercise style is "fill in the blank" so it's not as rigorous for learning, but still fun to get a sense of different language concepts.

[+] agumonkey|8 years ago|reply
Similarly, what I liked the most about programming MOOCS was the online test/grading server. It gamified the learning, and was very stimulating for me. At one point, all "quantitative" subject learning platform could probably just be a grading server plus exercises.
[+] weavie|8 years ago|reply
I agree. Good exercises will make you realise that you haven't actually read the chapter properly and you should probably go back and actually pay attention!
[+] smt88|8 years ago|reply
I've always made my own exercises by deciding what I want to build with a language before I build it. Then I break it up into chunks and learn as I go.
[+] dumindunuwan|8 years ago|reply
Thanks for the feedback! It's a good idea to add questions section at the end of each section.
[+] _Chief|8 years ago|reply
From the github readme

> I am a Sri Lankan Web Developer who lives in Vietnam. So I am not a native English speaker and just learning Rust

This guide is so well done, props to you. I haven't worked with Rust yet but your docs make it seem so easy to work with.

[+] hokkos|8 years ago|reply
I love those succinct introductions to languages, I find it easier to understand when you don't have to read lots of text and languages possibilities are written as a series of quick examples.

What I miss from Rust learning material is a series of exercises that focus on reference, lifetime, ownership where you have to fix some code to make it compile.

[+] vvanders|8 years ago|reply
Looks really nicely written and laid out.

One note on borrowing/ownership that really made it click for me was that to move from &mut T to &T you have to transition through owning the value type, so:

&mut T -> T <- &T

Whichever scope holds the actual value-type is the only scope that can make that transition(absent cases like RefMut)

[+] microtonal|8 years ago|reply
Could you clarify you mean here? Something like this is perfectly valid:

  fn no_mut(a: &mut usize) {
    *a = 10;
    let b: &usize = a;
    println!("a: {}, b: {}", a, b);
  }

  fn main() {
    let mut foo = 42usize;
    no_mut(&mut foo);
  }
If such pointer weakening was not possible, how would you be able to call a method that takes &self on binding of type &mut self? Of course, you can't use a mutably while b is in scope. So, something like the following results in a compiler error:

  fn no_mut(a: &mut usize) {
    let b: &usize = a;
    *a = 10;
    println!("a: {}, b: {}", a, b);
  }
[+] red75prime|8 years ago|reply
Downgrading &mut T to &T is perfectly valid in every context[0]. Upgrading from &T to &mut T is impossible in safe Rust and can easily cause undefined behavior when it's done in unsafe block. If you have T, you can create one &mut T reference or many &T references.

[0] Except in a case when there's &mut U reference, which points at some part of the object referenced by &mut T.

[+] Scarbutt|8 years ago|reply
For devs, equally familiar in rust and python and ignoring libraries, would you say development speed in both languages is almost the same?
[+] siscia|8 years ago|reply
I really don't think that I could code any faster of what I code in rust. Especially if you consider the overall quality of the work.

In my humble opinion python give the impression to move fast, but when you need to maintain the code base the rust compiler is simply too wonderful.

[+] always_good|8 years ago|reply
Higher dimensional things are trivial in other languages while they are nonobvious in Rust.

For example, this week I was working on a mechanism for one request to start a future and then all further requests for that resource to await that same future.

I implemented it in less than 5 minutes in Node by just storing Promises in a map. But I'm still not sure of the ideal solution in Rust. It's definitely outside of my familiarity zone.

But what I'm finding over the months is that my routine Rust code is pretty fast now once I've run the gauntlet of experiencing the same compiler errors over and over. And when I reach for Rust instead of Node or Python, it takes longer but my executable is 3mb and it's much faster without much additional expense.

Also, it's tough to do async work in an ecosystem that isn't async-everything, something easy to take for granted in Node and Go.

[+] mlindner|8 years ago|reply
For me writing Python is fast, until you need to rewrite it when you inevitably refactor. For Python that's an agony, for me.
[+] staticassertion|8 years ago|reply
I write python for most of the day, professionally. I write Rust at home.

I'd say I spend similar time on the same problem with both, maybe a bit more upfront on Rust and a bit more on the tail with Python. This is, of course, disregarding libraries.

[+] mquander|8 years ago|reply
I'm more familiar with Python than Rust right now, but I feel like after adjusting for amount-I-have-to-look-up-standard-library-things my development speed is similar. The biggest advantage Python gets is IPython.
[+] piracykills|8 years ago|reply
I really want to learn and use Rust, but just lack the motivation, especially when APIs turn out to be incomplete - I think the last one I saw was multicast not allowing me to set the send interface.

I guess the main draw for me to any given language is great libraries with great APIs. Python has those, Javascript has those, C++ has those, Rust... not so much yet.

[+] childintime|8 years ago|reply
> I guess the main draw for me to any given language is great libraries with great APIs. Python has those, Javascript has those, C++ has those, Rust... not so much yet.

Well... what makes (especially) Rust libraries great is the relative absence of bugs. I can use a Rust library and have great confidence some ugly bug won't bite me later on. The developers of the libraries you (don't) mention continuously struggle to achieve the same property.

So in a sense those libs are not at all great in the same sense that a Rust library is!

[+] earenndil|8 years ago|reply
This looks like a fairly nice website. For someone coming from a background of C and D, but familiar with quite a few others, I have to ask: what makes rust different and better? Aside from memory safety, what reason do I have to choose rust over another language?
[+] mykull|8 years ago|reply
Good (and improving steadily) compiler feedback, centralized package manager, thoughtful approach to language versioning, a syntax that I like (very subjective), and the flexibility to write unsafe code blocks if for some reason you need to. Those are some of my reasons for liking it.
[+] Drdrdrq|8 years ago|reply
Resource safety and expressiveness on level of Python (or close) combined with speed of C.

That said, while I love the idea of Rust I find the language itself offputting somehow. I don't know, maybe I just need to give it another try.

[+] Paul-ish|8 years ago|reply
Did you have another language in mind? Eg Rusts safety means basically nothing if you are comparing it to Python or C#.
[+] talloaktrees|8 years ago|reply
How does this compare to the Rust Programming book?
[+] rayascott|8 years ago|reply
Programming Rust has 21 chapters and is 583 pages long. I’ve read it, and I’ve also read the online Rust Book (both several times). Most chapters are in the order of 20 to 30 pages long. Programming Rust is one of the best programming books I’ve ever read, and I’ve been coding professionally since 1997. If you want to get an A+ in Rust read Programming Rust a few times. You can see the entire Contents section of the book on Amazon. Below is a list of chapter titles from Programming Rust that get little to zero coverage in this Learning Rust website.

Ownership. References. Expressions. Error Handling. Enums & Patterns. Operator Overloading. Closures. Iterators. Collections. Strings & Text. Input & Output. Concurrency. Macros. Unsafe Code/FFI - the coolest part, they show you how to create a safe wrapper around libgit2.

[+] dumindunuwan|8 years ago|reply
My target is preparing a short and sweet way to learn Rust.
[+] anon335dtzbvc|8 years ago|reply
[+] dumindunuwan|8 years ago|reply
At that time search was not working, had bit ugly ui, no indicator for current page and etc. Even it's duplicate, this time people actually saw it correctly. So sometimes trying things again is a good thing :) Have a nice weekend!
[+] always_good|8 years ago|reply
That was three months ago...

Do you expect people to start participating in that submission with zero comments now that it's three months from the top of the stack?

[+] yusrilhs|8 years ago|reply
I trying use rust, but I don't know why sometimes cargo is like hanging to retrieve from github.
[+] Wildgoose|8 years ago|reply
If you are going through a proxy server (e.g. at work) then you may find that the SSL interception proxy has not been correctly configured to provide revocation information.
[+] steveklabnik|8 years ago|reply
Please file bugs! We'd like to track it down.
[+] Animats|8 years ago|reply
I used to know Rust, but I got tired of the churn and went back to Go.
[+] steveklabnik|8 years ago|reply
What churn, specifically?

Anything you learned since May 2015 should still be very relevant. That's almost three years ago.

[+] Dowwie|8 years ago|reply
Examples or it didn't happen