i have a rust programming language 2nd edition book dilemma in using it.
chapters 1-5 have working examples with main functions. it is easy to follow. the chapters after 5 have only snippets without any main functions. it is hard to follow. i tried downloading the source code. all it has only cargo scripts in md files.
any tips or suggestions on how to continue with this book?
some lines of the example code, including the main function, are hidden using a feature of mdbook for brevity. unfortunately, these hidden lines are lost in printed media.
but don't worry, the books is also available online, (and also installable offline with rustup). in the browser, there's button next to example code snippets to show hidden lines. you can also run the code (powered by the playground) to view the output if there's any.
reading online:
reading locally:
# install the docs in case not already done
# this command only needs to be run once
$ rustup component add rust-docs
# open the book using your default browser
$ rustup doc --book
My advice: read Programming Rust instead. The chapters are much better organized and it's a more didactic book overall (I did read The Rust Programming Language 2nd Edition after, for comparison).
Mind, it expects the reader to have programmed in another language before.
That is a very opinionated recommendation ![]()
I read it six months after the official tutorial. It is a good book, and Jim Blandy obviously knew a lot of Rust, and they explains it quite well. Indeed I am considering buying and perhaps even reading the upcoming third edition.
But my feeling was, that they did not really cover all the stuff of the official tutorial. They discuss a lot of details -- perhaps too much details for a beginner. And the order in which they present it? I was not too happy with it, but I was also not happy with the topic order of the official tutorial book. For me a beginner book for a language should present the core concepts early, and provide the reader with all the foundations in the first 100 to 150 pages, so that the reader can early decide if the language is actually useful for them, and already start coding. Both books cared not too much for this strategy, e.g. both presenting testing and other less important concepts early. And of course the second edition of Jim Blandys books had also some issues -- I might have found only a dozen, but that is why I read it quite fast and because I am not a native English speaker. I was even going to report a few, but then with Google search I found a list with many more issues, so I have reported none. I hope they will fix most of it for the third edition.
So actually Jim Blandys books is quite good -- one of the bests Rust books, but in my opinion more to read after the official tutorial. And my general advice: Never actually buy a book, as long as you are not sure you will really need/use/enjoy it. Some decades ago I bought a few programming books spontaneously -- and then discovered that the language is not the right choice for me, or that the book is just too bad.
And for the OP -- when they had already trouble following the examples of the official tutorial (and even finding the shift key on the keyboard) I would not recommend to start with Jim Blandys book.
[EDIT]
Not that I want to say testing is not important. It is just, when I learn a new language, testing is not very interesting for me. I care for testing, when I have decided to really continue using the language.
[EDIT 2]
A beginner book might not care that much for the order of topics, when there is a fine short online tutorial available. Twenty years ago I started with Ruby -- first with a nice semi-official tutorial (I think there were even two) and then bought the paper book of the Ruby inventor and main developer. That learning strategy made sense for me that time.
We probably all have slightly different expectations, so I agree that's somewhat opiniated. ![]()
I remember that Programming Rust (PR) started with a tour of the language in the first 50 pages or so, even showing a multithreaded application (Mandelbrot), which I found very interesting to get a first general idea of Rust. It also spends some time on asynchronous programming, which I didn't find in the other book.
On the other hand, TRPL explains a few other things more accurately, like the Cargo.toml configuration and the subtleties of version numbers. It also benefits from the feedback of the community.
What I mainly reproach to TRPL is the "negative" approach: first show code that doesn't work, and then show the proper way (except they sometimes postpone the correct version and, in one case, even forget about it). But maybe some people like it. Also, the order in which the concepts are introduced seems more natural in PR: even if it's probably not perfect, there weren't all those "we can't continue right now because we need that concept, which is introduced only in a later chapter"—way too frequent in TRPL and which confused the hell out of me.
That's why I advised another approach to the OP when it didn't seem to work. But you're right that it depends on exactly what was hard to follow; I interpreted it differently and could be wrong.
PS: I agree with you about that damn shift key that seems broken on several users' keyboard, here. Doesn't make it easy to read for the rest of us... ![]()
stafan was right. i did not go so well as beginner. but tyvm anyway.
I see that the examples in TRPL are here and seem complete with cargo files and all:
Was it where you looked?
But I see that this is the ongoing code listing for the future 3rd edition, despite an existing branch for that purpose. And unfortunately, there's no tag or release for the 2nd edition, so it's a bit of a mess. If the examples above don't match the book closely enough, you could try this revision, which corresponds more or less to the time of publication (be aware it's for older versions of Rust, though it shouldn't be a problem):
You can download everything with this link. Then check under "listings".
In case it helps, you might also find this website helpful: Rust by Example.
Omg. Finally, complete simple workable examples. Tyvm, I can continue with the 2nd edition with its incomplete content. i still cannot believe that the book example listings died after chapter 5 and they published it. Where were peer and pre-release publisher book reviews? I would get heavily hammered at the job if i published anything without pre-release reviews.
You're welcome.
I suppose that one reason is that if they listed the whole code each time, it'd take a lot of place in the book, and it'd be more difficult to do the layout without splitting the code between pages.
But more importantly, the excerpts show only the code that's relevant. Personally, I find it much easier to read like that, and I'm pretty sure most books do the same.
For example, Listing 7-18 shows the change discussed in that section by regrouping crate items:
use std::{cmp::Ordering, io};
instead of the more confusing chunk below where you'd have to retrieve the relevant code and where none of the rest adds anything (I removed empty lines to make it shorter):
use rand::Rng;
use std::{cmp::Ordering, io};
fn main() {
println!("Guess the number!");
let secret_number = rand::thread_rng().gen_range(1..=100);
println!("The secret number is: {secret_number}");
println!("Please input your guess.");
let mut guess = String::new();
io::stdin()
.read_line(&mut guess)
.expect("Failed to read line");
let guess: u32 = guess.trim().parse().expect("Please type a number!");
println!("You guessed: {guess}");
match guess.cmp(&secret_number) {
Ordering::Less => println!("Too small!"),
Ordering::Greater => println!("Too big!"),
Ordering::Equal => println!("You win!"),
}
}
Now, it was just a quick look. It's possible that some listings are more confusing when they're incomplete, but that's something one usually builds and updates in their head when reading a book.
so far, I have experienced incomplete listings with main fns that displays unused variable name warnings. i use either println statements or fix let statements to resolve it.
Excellent. You are learning how to understand error messages.
Just keep going. Typing and fixing what is missing will help the learning stick in your brain.
Since I got the listings, i will keep going.
I seem to understand that it doesn't cover testing.
Sorry, I might have confused that with the official tutorial, which introduces testing quite early. But I think the book of Jim Blandy had introduced other important and very useful topics like collections and container types really quite late, after discussing crates and modules. I had reversed that order -- but of course that is a very opinionated personal view.
Yesterday I had a short look at the book "Effective Rust" which is also available online. I think that book is not that bad, it is some form of repetition of the most important concepts of Rust.
Initially I was going to fully ignore it, due to the very bad and totally misleading summary of the back cover on the OREILLY page, which you can also read at the Amazon book page. It tells us
Beginner to intermediate
If you're a software engineer who has experience with an existing compiled language, or if you've struggled to convert a basic understanding of Rust syntax into working programs, this book is for you.
This back cover page is fully useless and misleading. The book is definitively not intended as your first Rust book, but more as a repetition and in depth discussion of some advanced topics. Well, I have only read a few online pages, but that it is not a Rust beginner book is obvious.
I confirm it covers testing (and, as I mentioned, asynchronous code). But I don't think the OP had a problem with testing; rather with the code examples. Their GitHub is confusing, but the problem was fixed above with a link to an older revision, although the OP didn't mark the solution.
For Programming Rust, there's a GitHub with all the examples, too.
It's a very good book, indeed, and definitely not meant as a stand-alone introduction to Rust. It's worth reading in parallel with either Programming Rust or The Rust Programming Language, since it's a valuable complement, or maybe after as a reinforcement of the important topics (which is what I did).
To be honest, I don't really see how the cover is useless or misleading. I don't see where it says or implies it should be a first book on the language. In fact, it's quite how I'd describe its content. Maybe I misread it.
Well, your short note
It's a very good book, indeed, and definitely not meant as a stand-alone introduction to Rust. It's worth reading in parallel with either Programming Rust or The Rust Programming Language, since it's a valuable complement, or maybe after as a reinforcement of the important topics.
Gives a lot more useful and important information than their back cover text. So lets have short look at Effective Rust [Book]
Category: Beginner to intermediate
Beginner is definitely wrong. I would guess they label it this way, as their might be more people interested in buying a beginner book.
Rust's popularity is growing, due in part to features like memory safety, type safety, and thread safety.
Not wrong, but not helpful as a description of the book.
But these same elements can also make learning Rust a challenge, even for experienced programmers.
Also in no way a description of the book content.
This practical guide helps you make the transition to writing idiomatic Rust—while also making full use of Rust's type system, safety guarantees, and burgeoning ecosystem.
A quite broad statement. And I would not call it "a practical guide"
If you're a software engineer who has experience with an existing compiled language, or if you've struggled to convert a basic understanding of Rust syntax into working programs, this book is for you.
From this sentence I got the strong feeling that it is an introduction to Rust for people with same experience in another compiled language.
By focusing on the conceptual differences between Rust and other compiled languages, and by providing specific recommendations that programmers can easily follow, Effective Rust will soon have you writing fluent Rust, not just badly translated C++.
This sentence is OK.
>Understand the structure of Rust's type system
>Learn Rust idioms for error handling, iteration, and more
>Discover how to work with Rust's crate ecosystem
>Use Rust's type system to express your design
>Win fights with the borrow checker
>Build a robust project that takes full advantage of the Rust tooling ecosystem
For me this list points again more in the direction of a standalone beginner book.
Actually this back cover text is a bit better than
But still I have the strong feeling that these back cover texts are created by trainees, who copy together a few common phrases.
For both books, the actual content seems to be significantly better than the back cover text. I also read a few pages of "Command line Rust" at Google books. While the content is quite trivial, and has nearly no new information for me, it is quite well written, and I think for very inexperienced peope it might be a useful second Rust book. Only their style of writing in first person singular "I will show you in this section ..." sounds a bit strange for me.
Note that my remarks about the actual content of the two books might be not fully correct, as I have only read a few pages yet. With "Effective Rust" I might actually continue, it seems to be a good resource to refresh my memory. It is quite well written and not too boring.
I don't fully agree. After all, it gives the important points for a beginner. It doesn't mean that it should be the first and only book one should read to learn Rust. "Beginner" is vague, anyway.
The author clearly states in "Who This Book is For", first page, that is meant to be the 2nd book a newcomer to Rust might need. But the most obvious hint is in the title: "35 Specific Ways to Improve Your Rust Code". It clearly says it's the type of book that contains a list of "recipes" or specific points of attention, and not a full tutorial to learn from scratch.
There are other hints that this book is only a complement:
This practical guide helps you make the transition to writing idiomatic Rust—while also making full use of Rust's type system, safety guarantees, and burgeoning ecosystem.
If you're a software engineer who has experience with an existing compiled language, or if you've struggled to convert a basic understanding of Rust syntax into working programs, this book is for you.
And the remaining part is quite explicit on the content:
By focusing on the conceptual differences between Rust and other compiled languages, and by providing specific recommendations that programmers can easily follow, Effective Rust will soon have you writing fluent Rust, not just badly translated C++.
Maybe it's possible to improve it, and, frankly, a book cover is also made to advertise it, but I didn't find that dishonest or misleading.
The best way to get an idea about programming books is to look at the table of content. Nothing guarantees that a book is good, though; for that, you need to read a few reviews.
Stafan,
tyvm. for reminding me to mark the post reply with the soilution. i marked it.
Personally I'd consider pretty much anything up to about a year (at the extreme) valid to call "beginner" for a language, though really it's more of a state of mind than anything else.
The best rule of thumb I can think of is you're an intermediate when you can read any code in that language without trouble, and you're an expert if you could have written any code in that language, (modulo domain knowledge). That was on the spot though, so I'm sure there's plenty of flaws with it.