The best approach to learning Rust

Hi

I've heard lots of great things about Rust, I have mainly a web development background, so Python, PHP, JavaScript etc, with some Swift iOS in there too. But I've never done lower level programming, so I was interested in having some ideas from more experienced developers on the best way to learn Rust for my situation. I had a brief look on Amazon at some titles, but though they seemed great, they seemed to be more for C/C++ developers, so I was concerned that I wouldn't have enough understanding of systems to apply Rust language

So long story short, what would people suggest as the best ways for me to learn rust. Open to books, tutorials, udemy or whatever you guys think.

Thanks :smile:

7 Likes

Approaches vary from person to person. The best way is to read the docs. One approach I used is to go through random Rust repos on github and understand how code is structured and other stuff. Also work on a proper project while learning as this ensures you touch the depths of the language.

3 Likes

What worked for me was reading the official book (it is great) and implementing a medium-sized program (this ray tracer) along the way.

I definitely recommend ray tracer as a programming project: it allows to explore a lot of different aspects of a language, and it takes only a couple of weekends to do.

5 Likes

What is the link to the official book?

All the links are here: Learn Rust - Rust Programming Language

The book, in particular, is this one: The Rust Programming Language - The Rust Programming Language

1 Like

Thanks :slight_smile:

1 Like

I myself started out with the book and lots of blogs by the different rust people (Manishearth, Steve Klabnik, aturon, burntsushi and many things linked from this week in rust)
This gave me a LOT of theory.

To actually apply that theory, I started the exercism rust track (flailing attempts recorded for posterity here).

What helped me really get to grips with the reality, and by far the most intense learning experience, was optimising/porting a program my colleague was trying to write in C.
I managed to convince him to Rust just in time, before he got started, and in explaining things to him, I learned/had-to-double-check a lot myself. That experience is documented here on the forums)

What also helps is browsing the #help category here on the forums, and trying to either figure out how you would do the same thing, or learn from the many helpful people answering the question :wink:

8 Likes

I have started by reading the Rust book, but at some point the mere reading was not enough - without the practice the information fades away... So I took a real-world project (a C#-based network management and provisioning system which I had previously moved from Windows to Linux using mono), and started to rewrite the pieces of it - it had conveniently several standalone processes which were doing well-defined tasks and are small enough - reachability checker, syslog server, configuration updater, etc.. I have about a month to get as much of it running as possible before it will need to do the "real world" job - but I have the C# components to fall back on, which were already battle-tested.

This proved great as a learning approach: Starting at first with diesel for basic database interaction and simple web-based queries, then ssh2, git2, etc, and having the need to make these interact together exposes a good way to get a feel for the borrow checker behaviour - even though I have read the stack overflow question, the details of "how to make it work" remained unclear until after maybe a day or so of hitting the wall I got the "Ah-ha!" moment, and could progress further.

Of course, also heavily relying on examples in the docs, too, and refreshing by random re-reading of the book, but now I reinforce the learning by needing the language features as solutions to "real" problems that I face (sometimes these problems are of my own making, like this unnecessary (ab)use of macros. In the end I came to a much simpler and elegant solution, but got a bit of handle on the use of macros.

After a few of the "how does it work and why I can not get it compiled?" occurrences I also have started to grab the source of the crates, and peek there - rather than merely looking at the type signatures.

So, my (beginner) opinion - pick a non-constrained project in some other language, preferably more backend/low-level (I can not say about frontend as I did not move to rewriting the frontend portion yet), for which you are comfortable with knowing the use case and which can be modularised into small independent pieces, and rewrite parts of it in Rust.

So - good luck and enjoy it. It's not very easy sometimes but certainly the joy once you "make it work" very rewarding!

p.s. also: I want to take a chance to thank a lot all the kind folks with whom I have interacted so far, both here and on stackoverflow! I do my homework, but sometimes it takes a second pair of eyes to notice the obvious :slight_smile:

3 Likes

I was really interessted in Rust. So like almost everyone, the first thing I did was reading the book. I watched some tutorials on Youtube at the same time.

Then I wanted to go for it, so I started to write a complete Window Manager for Linux with Rust-XCB. I completely failed at that. (I still successfully ported tinywm-xcb to rust: tinywm-xcb-rust).
I failed because not only because the task in itself was too big, but also because the documentation for XCB is inexistant...
Still, this forced me to learn how to use Rust's auto generated help, which is really important and really well designed.

I then thought about converted my own PHP backend for my website to Rust. This time, I succeeded. With the help that everyone has given me here, and by reading other posts, I learnt a lot.
By doing this, I also had to take part to a project, this was my first, I took part in the rust-ftp project because I needed it. It simply didn't work, and since there hasn't been any update for a while, I decided to make it work myself.

This is where I'm at right now. I am considering retrying on the Window Manager project, maybe with Wayland ? Maybe with the Rust-Xcb fork that I just found ?

p.s. : Lifetimes and borrowing (and references). This is the two features than I still don't always understand. For me they are the most complicated concept in all of Rust. I hit the This variable does not live long enough error a lot, or This variable is borrowed here, etc.

Rust is an amazing language with which you can do what you want, the important thing is just to do it. Take a project that you want to write in Rust, search for crates that can help you and do it.

4 Likes

Something I always like to do when trying a new language is write a compiler for a toy programming language. It gives you a good feel for the more complex data structures, as well as string manipulation and working with bytes, plus most languages have decent bindings to llvm by now.

Another nice beginner project is to rewrite an application you've previously written in another language (e.g. my github-backup or rustc-internal-docs). Interestingly enough, I found that Rust is a pretty decent replacement for the modestly sized (1-2kloc) Python programs I've previously used for command line stuff. Rust turns out to be really good at dealing with errors and enforces good design, resulting in super reliable programs. Libraries like clap and serde make it just as powerful (if not more) as the more "high level" scripting languages like Ruby or Python.

8 Likes

Even though I don't know functional programming this guide is more useful than anything else I found (perhaps because it is being honest.)
http://science.raphael.poss.name/rust-for-functional-programmers.html
I'm still not sold on rust. I want to know what useful things are in the standard libraries that I can use. Instead all I get is a wall of type system information. I'd like to peek over the wall and see what you can practically get done in the language.

When you do peek over the wall of type system information, be aware that Rust's standard library has a very different goal from other standard libraries like, say, Python's.

Python's philosphy in this regard is "batteries included". That is, the standard library contains everything could probably use at some point.

Rust's standard library, on the other hand, only contains the things that you are very likely to need because they're so ubiquitous. As such, it is much more limited in its scope. When writing my first project, I found that I had to reach out to third-party crates very quickly, even for tasks I considered "simple". Luckily, Cargo makes it very easy to pull in dependencies. <3

If you'd prefer a batteries-included approach, there is a crate called stdx that is supposed to offer the missing batteries. Though I have to admit, I haven't used it, so I can't make any promises about how useful it actually is.

4 Likes

This resource is from 2014, and so has inaccurate information on it, just so you know.

1 Like

I am considering retrying on the Window Manager project, maybe with Wayland ? Maybe with the Rust-Xcb fork that I just found ?

Have you seen way-cooler? It's a window manager for Wayland written in Rust, I'm sure you could steal code find some inspiration from that project. It looks very cool.

p.s. : Lifetimes and borrowing (and references). This is the two features than I still don’t always understand. For me they are the most complicated concept in all of Rust. I hit the This variable does not live long enough error a lot, or This variable is borrowed here, etc.

I ran into this too, when I was learning Rust. I started learning in 2014 (ish) and didn't start getting my hands dirty until this year. I think I'm finally at a point where I understand lifetimes and borrow checker errors, and how to mitigate them (which usually ends up throwing my head in my hands when I realize I made a wrong assumption somewhere down the line). It's incremental for sure, and persistence is key. Keep it up :slight_smile:

2 Likes

Yes, I will definitely steal code get my inspiration from them :stuck_out_tongue:. It looks like a really good WM but it still doesn't have the features I want, and going through the code won't give me enough knowledge to maintain it either, so I've decided to create mine using wayland, but it will be closer to i3 and I don't think it will have configs as a may priority (it will be like DWM, go into the code and change it there).

I think I do too, but I haven't gotten into the multithreading side of things yet.

Yeh, I'm aware that resource is out of date. You know the D programming language had very strong initial support. However constant meddling in the basic specifications (including 2 different branches) led to rapid abandonment. D never really recovered from that.Like a lot of people I'm finding the Rust typing system poorly articulated. All I need is a set of examples with the actual state each variable is in documented at each line. I'm sure there is a simple logic behind it.

steveklabnik
November 29 |

This resource is from 2014, and so has inaccurate information on it, just so you know. Visit Topic or reply to this email to respond.
In Reply To

S6Regen
November 29 |

Even though I don’t know functional programming this guide is more useful than anything else I found (perhaps because it is being honest.) Rust for functional programmers · dr knz @ work I’m still not sold on rust. I want to know what useful things are in the standard librar… Visit Topic or reply to this email to respond. To unsubscribe from these emails, click here.

This might not be the exact kind of resource that you would need but have you checked out the
rust-cookbook? Its more focused on what you can do with crates than stdlib but a lot of people found reading (and contributing) to it helpful as well as a nice way too get their feet wet in rust.

3 Likes

I'll have a look at the rust-cookbook and see how I get on. Maybe Rust is something to get back to a bit later because I have real world projects to get on with. Or something that will necessarily take some time. The GC-less memory management and concurrency aspects seem very good in theory. I can manage threads and memory well enough for the small projects I do without compiler support though. It's just if Rust can make my code more concise then it could be worthwhile.

budziq
November 30 |

S6Regen:I’m still not sold on rust. I want to know what useful things are in the standard libraries that I can use.
This might not be the exact kind of resource that you would need but have you checked out the
rust-cookbook? Its more focused on what you can do with crates than stdlib but a lot of people found reading (and contributing) to it helpful as well as a nice way too get their feet wet in rust. Visit Topic or reply to this email to respond.
In Reply To

S6Regen
November 29 |

Even though I don’t know functional programming this guide is more useful than anything else I found (perhaps because it is being honest.) Rust for functional programmers · dr knz @ work I’m still not sold on rust. I want to know what useful things are in the standard librar… Visit Topic or reply to this email to respond. To unsubscribe from these emails, click here.

I'm not sold on Rust, either. I've ported several programs (from a finance suite I've developed) to Rust and got them all working, with varying degrees of difficulty. The primary issue for me is the cost in development time/difficulty of memory management without a garbage collector. Most of the posts you see here by confused people are related to this (problems with the borrow checker and lifetimes). We are fortunate to be programming at a time when computing resources are so plentiful (memory, processing power) that most of the time what we need to optimize is software development time, because that's where the costs are. We are no longer living in the world that I did when I first started programming 50+ years ago, where the hardware was at least 3 orders of magnitude less capable than we have today, and our focus was, and had to be, making life easier for the computer. That's where the cost was then.

I am not arguing that Rust has no value. Hardly. I am simply arguing that its applicability is not as broad as some people seem to think (though I don't think this is the fault of the Rust developers or documentation writers; right on the rust-lang.org page, the language is described as a "systems programming language", which strikes me as entirely appropriate). I don't think the cost-benefit proposition justifies using Rust for most userland applications. Said another way, most of those applications will function just fine in an environment with memory managed by a garbage collector. In fact, a lot of that code would be fine in an interpreted, garbage-collected environment, though their dynamic typing can be a debugging detriment compared to Rust's static typing. But Go and Haskell offer the same static typing advantages, without the tyranny of the borrow-checker and the still-not-adequately-explained lifetime system.

2 Likes

That sounds like the PHP idealogy. Computer resources might be plentiful but that doesn't mean we can disregard performance.

1 Like