Programming Rust: Fast, Safe Systems Development (英語) ペーパーバック – 2017/12/21
Kindle 端末は必要ありません。無料 Kindle アプリのいずれかをダウンロードすると、スマートフォン、タブレットPCで Kindle 本をお読みいただけます。
Rust is a new systems programming language that combines the performance and low-level control of C and C++ with memory safety and thread safety. Rust’s modern, flexible types ensure your program is free of null pointer dereferences, double frees, dangling pointers, and similar bugs, all at compile time, without runtime overhead. In multi-threaded code, Rust catches data races at compile time, making concurrency much easier to use.
Written by two experienced systems programmers, this book explains how Rust manages to bridge the gap between performance and safety, and how you can take advantage of it. Topics include:
- How Rust represents values in memory (with diagrams)
- Complete explanations of ownership, moves, borrows, and lifetimes
- Cargo, rustdoc, unit tests, and how to publish your code on crates.io, Rust’s public package repository
- High-level features like generic code, closures, collections, and iterators that make Rust productive and flexible
- Concurrency in Rust: threads, mutexes, channels, and atomics, all much safer to use than in C or C++
- Unsafe code, and how to preserve the integrity of ordinary code that uses it
- Extended examples illustrating how pieces of the language fit together
Jim Blandy has been programming since 1981, and writing Free software since 1990. He has been the maintainer of GNU Emacs and GNU Guile, and a maintainer of GDB, the GNU Debugger. He is one of the original designers of the Subversion version control system. Jim now works on Firefox’s web developer tools for Mozilla.
Earlier today I went looking for my first "Rust book", as Rust is at the top of my list as the next computer language that I want to learn. I started back in the 1970's with FORTRAN on CDC servers, and then with C inside Bell Labs on PDP 8's and 11's. Kernighan and Ritchie's original 1978 "C Programming Language" is the oldest "classic" language book on my shelf, which, like this Rust book, I purchased shortly after it was published.
Hopefully I will remember to return to this review, once I have gotten further into it. But so far, it's looking like a potential "classic."
Update #1: I've gotten a quarter of the way into the book. It's most excellent so far, combining a rare mix of a readable, conversational style with a coherent organization and meticulous accuracy both in the detail and in the conceptual, by a couple of authors who know their stuff, both Rust and systems programming. Unless the authors are the 1 in a 1000 who write polished prose in the first draft, there's the mark of some dang good editing here too.
Update #2: This book (at least the Kindle version I'm reading) lacks a Table of Contents, which I miss. The book is quite well organized, by chapter and subchapter, so I'm not sure why there is no Table of Contents. Perhaps the hardcopy edition will have such, but the "location" rather than "page number" positioning of a Kindle book makes a Table of Contents more difficult?
Update #3: Oops - sorry - there is a table of contents in the Kindle version. It doesn't appear as part of the inline text such as after the title and copyright pages, before the Introduction. Rather it's a special Kindle accessible table of contents (look for the 3 horizontal bar menu pull down icon, near the upper left), which you can access from any "page" in the book.
It's important to note that this is *not* a book for the novice programmer. It's a book for someone who knows one or more *other* languages well, and wants to start using Rust to build applications. Since Rust is designed for systems programmers, many of the comparisons are to other systems languages such as C, C++, and Java.
Compared to languages like Go or Python, Rust can be a bit adversarial for the beginner -- what experienced rusaceans refer to as "fighting with the type checker". Most of the reference material available online either assumes familiarity with Rust's checks, or explains it using formal rules. Neither approach is particularly helpful when you're fighting. Jim and Jason explain type and borrow checking from a practical perspective, highlighting a few common design patterns and how they are implemented in Rust (or why they are difficult to implement in rust).
I've been hacking away in Rust for a year or so now, writing toys and fiddling with Rust features, but only having finished this book do I feel like I could successfully design and build a large application in Rust.
The chapter on concurrency, which really showcases the power of Rust's memory safety semantics, was probably the most illuminating. I remember the "ahah" moment I had learning about Elixir's concurrent data pipelines with channels, yet Rust supports this just as easily - and several other concurrency models to boot.
Just about my only criticism is that I thought the chapter on Generics could have used more and simpler examples, to build a better mental model of how they work. I still feel a bit weak on some of the more complex generic type definitions, and will have to read a bit more about this. This and a few other areas lead me to believe that this book is probably better approached by someone with an extensive background in systems programming (particularly with C++), which I do not really have (have only used C++ at a basic level years ago).
Highly recommended to anyone making a serious attempt at learning Rust - a seriously impressive language that has a lot of promise at modernizing systems programming.