Learning Rust? Here's a book recommendation


#1

Here’s a copy of the review I just left for a book I recommend called “Programming Rust” at https://www.safaribooksonline.com/library/view/programming-rust/9781491927274/

If you’re interested in learning Rust (and particularly if you come from a C or C++ background), save yourself a lot of time and get this book. I read most of the 1st and 2nd edition free Rust books written by the Rust team, but those books often left me with more questions than answers.

(Quick: why have two string types, &str and String? If you dig enough, you’ll find that str is non-resizeable and always allocated on the stack, and String is resizeable with a heap-allocated buffer. But that doesn’t answer the question, actually. Why not have String be the only type, but with a small-string-optimization (SSO) to avoid unnecessary heap allocations? I’ve yet to find the answer to this question. And to be fair, so far, I haven’t read the answer to this question in this book either, but the authors do offer a rationale of this as a non-resizable+stack/resizeable+heap pattern that occurs in several places in Rust. This has helped (partially) clarify the motivations for the split(s) for me.)

Just about every page I’ve turned to has filled in background or context around Rust that I haven’t found elsewhere. At least in my case, this is exactly the learning and reference material I’ve been looking for.

Kudos to the authors!

I have no affiliation to the company or the authors; I just want to save others time and perhaps frustration if they’re picking up Rust.

The book does good things like list all Rust types in one place, explains exactly and succinctly when auto-dereference can occur (dot operator’s left operand, index operator’s left operand and both operands of all comparison operators ) and what constraints apply–those kinds of explanations are pure gold. The initial example programs are “hello, world”, a web server, followed by multi-threaded mandelbrot set generator, all in Chapter 1. I’m always appreciative when authors can get to interesting (and fun) examples so quickly.

Some things I found that might be of interest:

  • If, like I was, you’re not sure, you can read the entire book online for free for 10 days by signing up for a “Free Trial”. (I did, but ended up buying the book within 20 minutes, because it was already answering so many of my questions).
  • I got 59% off the eBook price by using a discount code at the checkout (purchase total came to a very reasonable $21): I did a quick Google search and I think the discount code I used was “WKEFRP”.
  • The online format downloads as .pdf, or .mobi (open-source e-reader format–compatible with Kindle app, for example).

I think this book is particularly good for programmers with a C or C++ background, like myself. I’m not sure about what one might expect when coming to Rust from, say, a web development background, but I can definitely vouch for the book if you are coming from C/C++.

Hope that is helpful to someone… Now, back to learning! :slight_smile:


#2

Of course that is a very nice book, I have it and I hope they end it up soon. But is better to not be in haste and get a better final product.

This is a specilly challenging thing because Rust is evolving too fast, but the authors are masters of low and high level programming so I have no doubt it will be achieved.


#3

The book is mentions v1.13 of the compiler, so it’s pretty recent. (It covers the ? operator, for example.)

But sure, there are plenty of things in the Rust world that are evolving. Personally, I am more focused on getting a solid handle on lifetimes, traits, the ownership model, etc. Ultimately I want to be fluent, like “here’s a compiler patch” fluent. :slight_smile: The language changes going on aren’t impacting my ability to understand these fundamental concepts and how they differ from those in C++, so it’s working well for me.


#4

I reviewed this book and can recommend it without reservation. It is comprehensive - the chapter on strings is 60 pages. It is incredibly high quality - I rarely had substantial criticism - and is filled with clever observations about small details. It also contains a number of informational tables and illustrations that can’t be found anywhere else. I’ve been working on Rust for 6 years and I learned plenty of new things from reading it.


#5

This looks really nice. Can’t wait until French bookstores get it. With O’Reilly, online shipping to Europe really isn’t a practical option, unless $50 delivery fees look right to you.

The french postal service, which is not particularly cheap, costs ~$25 for 1kg international shipping. And that is for individuals, companies get discounted rates from grouped purchases.


#6

Ouch!

I’m more of a soft-copy person, myself. I can have all my reference materials with me wherever I am, and soft-copy is searchable!! :smile:

Still, I understand–there’s something about flipping through a physical book that scrolling just doesn’t quite match up to.


#7

Quick: why have two string types, &str and String? If you dig enough, you’ll find that str is non-resizeable and always allocated on the stack, and String is resizeable with a heap-allocated buffer.

Unless I’m mistaken this is false: &str is not stack-allocated: it’s not allocated at all, unless you want to count the metadata (string location and size), but that applies to String as well.

I wonder where you (or the book) got this from. I tried reading the book, but it requires registration.


#8

I bought the book and found it a nice complement to the official documentation. The official documentation is great for understanding how to get things done, this book showed a lot of what goes on behind the scenes. Pictures showing how different things are laid out in memory, and what is happening in memory with a copy vs move helped reinforce ownership and borrowing rules listed in the official documentation.


#9

Hi, heftig,

Yes, to read the book for free, you do have to register.

Re: allocation, yes, you’re right. (Unboxed) str data is stored in either static memory, while String data is stored on the heap. Both types have headers in the current function’s stack frame.