Recently, I have been having some trouble with the official documentation. Although the responses to my thread have been very good, insightful, and useful, I do want to try another book than the official one that I found, to see if it matches my learning style better. This book is Programming Rust: Fast, Safe Systems Development, by Jim Blandy. Its publication date is 2017, however, and Rust's most recent edition according to the official documentation is that of 2018. As such, I am concerned that learning from the linked book (which I do think has a better style for me) will cause me to learn outdated information and thus make future work more difficult. The difference between 2017 and 2018 isn't that large though for some projects, and I really don't know what Rust changed in this time (nor do I know, for sure, which version of Rust the book covers — perhaps Rust 2018 was available in beta as it was written, and thus is covered). As such, I ask: Is this book a good source to learn Rust from now, when it is almost 2020?
I used the book and enjoyed it, but using it as a beginner now, I think it depends. For learning Rust, yes, I think it is still a great book. The book covers borrowing and traits very well, which is really the crux of rust.
Changes in Rust since the book came out are pretty minor; the biggest one that would affect code in the book would be the changes to the module system. But the compiler should be able to help you through that (or you could use edition="2015" in your Cargo.toml). Otherwise the code in the book should work fine.
It won't cover the Pin API, futures, or web assembly at all though. And some of the examples will use old versions of libraries. Using Cargo you can still lock into those older versions of the libraries for the sake of doing the examples.
I would still recommend it as a first Rust book.
As another owner of Programming Rust, I'd also recommend it, also today.
I find it a pleasure to read, both in front-to-back mode, as well as look-up-mode. It is characterized by a pragmatic focus, not just showing off cool features, but also explaining the value of those features with practical examples.
For me, it really solidified the relation between the actual memory, and Rust's type system.
Afterwards I understood "why even do ownership".
The examples are also well though out, and have a good mix of introducing concepts and being non-trivial enough that they feel useful and fun to do.
I'm also very happy with chapter 13 "utility traits", which finally made the "trait soup" click for me.
It helped me understand how powerful they are, and how traits like Copy
, Deref/DerefMut
, From/Into
and Borrow/ToOwned
make generic, and powerfully reusable, several core aspects of Rust's memory management.
I've just reviewed the table of contents, and agree with @ryan: about the only outdated section would be chapter 8 "crates and modules", and even there quite a lot still applies without change.
Macros have gotten a lot more powerful too, if I'm not mistaken. Again, the basics still apply, it's just that we have even more power to work with these days.
All the code in the book that compiled at the time of writing should compile today, thanks to Rust's backwards compatibility guarantees. As @ryan mentioned, you may need to put edition="2015"
in your Cargo.toml
to get the same behavior.
There may be cases where the book shows code that doesn't compile, and today it does compile because of improvements to Rust's analysis.
The Edition Guide covers all the differences between Rust 2015 edition code and Rust 2018 edition code.
Well, although it is a very good reference, but I wouldn't be recommending it for people wishing to learn about the new features introduced in 2018 (which is inherently obvious). The 2018 edition has undergone a huge number of changes, way too much to document in a single changelog got quite a lot of new things added, which is outside the scope of the aforementioned book. For anyone willing to learn Rust, this is a good starting point. If you want to learn about the new ways of doing things in Rust, added in the 2018 edition, then you can look up the edition guide, which documents quite a salient number of additions and removals that have happened as Rust evolves.
Another change which might confuse is nll; it may make things compile which the book expects to not since it breaks lexical borrowing sometimes. But that can be fixed, once again, by adding edition = 2015
. I've been around since August of 2018 and there hasn't been that much that has changed in terms of general rust. Macros may have changed a bit though. On the other hand, if you're looking at specific areas, say, web assembly, async and futures, then yes, you'll have a hard time learning about them from an older book which most likely doesn't cover them. Note that I read a good chunk of the book but I enjoyed trying things, reading docs and trying very hard to grasp every little detail about the core language (lifetimes are still quite confusing sometimes though, but that's only in niche situations) since I came feeling betrayed by C# that it hid alot from me and was frankly frightened by C++. I'd honestly say that the most crucial tip I could give you is that the language is designed (probably intentionally; I'm not sure though) to be intuitive from the get-go; things follow a pattern, there are few special cases, and even when there are there's a good explanation for why.
Can it? AFAIK the 2015 edition is using NLL too, or is it nightly-only for now?
This is correct. There are cases where edition = 2015
code now compiles where previously it didn't.
I believe @jimb is already working on a new edition of this book -- any ETA?
If you want a test reader for your new chapter(s) as someone who is actually trying to use it to learn, I'm happy to help.
Yes, I'm working on a second edition now. All code will be brought up to current releases (the 2018 Edition being part of that), including the crates and modules chapter, and we'll have a new chapter on async programming. The chapter on references does need to be updated to cover non-lexical lifetimes, but the intuitions are all still the same.
I think almost all of the book should still be helpful. Our focus has always been on explanation and getting readers to the point where they can learn the rest on their own, not exhaustiveness (that's for docs) or specification-level precision (that's for, uh, specifications), and that should age well.
O'Reilly is very, very keen to have the second edition out in 2020, as soon as possible; it's sold well. But I'm incredibly slow, so I think the first half of the year is unlikely.
(If you've ever thought about pitching a Rust book to O'Reilly, now is the time to do it. They're really impressed with Rust's momentum, and looking for authors. Drop me a note at jimb@mozilla.com.)
Yes, I'm specifically looking for readers who are not yet familiar with Rust. Comments from people actually trying to learn something from what they're reading are essential, because they provide insights into the clarity of the writing that, say, a technical reviewer checking for accuracy could not.
Please get in touch with me at jimb@mozilla.com.
I read the book soon after the 2018 edition came out, and I added annotations along the way. I did add several notes indicating that something had changed in the 2018 edition, but probably no more than a handful or two... across 500+ pages. (Unfortunately I don't have my annotated copy of the book with me, so I can't give you an exact number.)
And, yes, I highly recommend it, especially if you are comfortable thinking about programs in terms of pointers and memory layout. It is absolutely the book I would recommend for anyone coming from C or C++.
[quote redacted]
To be clear, the 2015 edition is not "Rust as it was in 2015"; it continues to be updated alongside the 2018 edition, so it is not the case that all the changes since 2015 are changes between the two editions. Editions are explained in great detail in the edition guide.
The difference between the editions is merely that breaking changes to the language as it was in 2015 (Rust 1.0) are usually only made in later editions. So, for instance, new keywords, such as async
, are only present in Rust 2018.
async
/await
is indeed an important new feature, and macros are also much more powerful in the 2018 edition. But the core language concepts are still the same, and I would venture to guess (without doing any specific numeric research) that most of the feature set and standard library is the same between the two editions.
Even where there are breaking changes, there are many cases where they can be fixed automatically, using cargo fix --edition
. You can even take advantage of non-breaking ergonomic updates (where the older, less-ergonomic feature still compiles in 2018) by running cargo fix --edition-idioms
.
As mentioned above, the main exception to the "no breaking changes in the 2015 edition" rule is a feature called non-lexical-lifetimes (NLL), which will be the default even for edition = 2015
code as of the next stable release (a week from today). In most cases, NLL allows code to compile that previously didn't, but in some limited cases it will cause previously-compiling code to no longer compile. However, any code that no longer compiles previously had a soundness bug, i.e., the compiler never should have accepted it in the first place.
It is impossible for the stdlib to change between editions, so they're the same in both
Aha, I had forgotten that!
Of course almost everything that's there in 2018 is there in 2015, except the new additions.
This is exactly what I meant
PS: I've updated my post
I'm at the last chapter of the book right now and can totally recommend it. Maybe exposure to C++ contributed to it as well but after going through the book Rust really clicked with me. And I've been playing with the language for a while. I don't recall many occurences when the book was out of date significantly (Zeroable
trade being gone is a recent example, but a minor one).
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.