The Rust Programming Language – Book Review

Rust Programming Language book coverRust is a language that has been showing up on various “top 10” languages to learn blog posts. If you believe the hype then Rust is the next “Java” and everyone is learning Rust. Rust in a nutshell allows a developer to program with the power of C or C++ without the common and troublesome issues associated with memory leaks and concurrency. Rust programs compile down to machine language similar to C or C++, runs without a intermediate run time and runs fast. With Rust you can develop at a low level of abstraction but avoid (most) issues associated with dangling pointers, bad reference, and race conditions. A developer would have to actually go out of his or her way to cause memory or concurrency issues. Don’t make the mistake that I did: Rust is the “next” or “better” version of C or C++. Rust is NOT a new flavor of C. Rust has its own syntax and just because you know C or C++ doesn’t mean you can just pick up Rust without spending some time learning the language.

The Rust Programming Language book is available in a print or web-based edition. I picked up the print edition at the local bookstore.  I like paper and have little use for reading a “web” edition.  If you choose the print edition make sure you choose the newest edition. This book already has a newer version that includes additions and changes to the language. You can find the web edition at: https://doc.rust-lang.org/book/. This book appears to be “the” book put out by the organization that manages the language.

The authors do a good job explaining how to use the Rust compiler and Cargo to set up, build and run Rust executable and libraries. Early on it dives into the standard data types, loops and then right into memory and ownership. This is where it gets interesting. Rust does not have a .Net type of garbage collection process yet it manages program memory and keeps you in the safe zone. In order to do this, Rust must keep a tight hold on pointers and references. These chapters explain how the code and compiler works to achieve this and how the developer will need to write code so the code will compile. There is a lot to understand and the concepts are used throughout the rest of the book so be well advised to have a solid understanding of these chapters.

The rest of the chapters cover everything from error handling which is different from or Java. There is no Try-Catch concept in Rust. Structs and enums are covered in depth with structs being the key construct to building encapsulated code. There is no class keyword in Rust but this doesn’t preclude Rust from being an Object Oriented language. Collections and Generics are covered as well as automated testing which is included in the language. Finally the book covers advanced topics such as concurrency, reference counting, unsafe code and pointers. A simple, multi-threaded web server project is included at the end of the book allowing readers a chance to put all the topics in the book to test.

This book covers the basics, enough to get you started writing console apps and libraries, but it still is only an intro. There are many libraries both by the Rust team and by the general Rust public that are not covered. The book doesn’t cover how to create web requests and data base connections. That’s not a ding against then book, but you will need more to get to a point where you can really use Rust in a day-to-day programming scenario. There are many books available that goes beyond the introduction to Rust but this is a book that will provide the basic understanding of the language and allow the read to move to more advanced readings.

My advice to readers it to plan on reading the book twice. Many concepts that you need to know in the early code examples are not covered till later in the book. The authors do point out that certain concepts will be covered in a later chapter. Reading the book through once with some hands on code examples followed by a more detailed read will make it easier to understand the earlier examples and better understand the language. It is the proverbial chicken and the egg issue – too show code you have to use features that have not yet been explained. Not a big deal.

Code books are a very technical read and this book is no different in that aspect. It does take some time to get through this book because of the technical info and details. Some of the concepts in the require the reader to really think about the covered concept before the reader can move on. There is a lot of code snippets to digest and try. If the reader is like me, knows C, C++, C# or Java, the reader will spend time attempting to rectify the Rust language to something they already understand. A word of advice to readers, make sure you understand the chapter on Ownership which is core to safe memory management.  Memory management is fundamentally different than C and if you don’t understand it, then you should not move on.

It does not take long to get a feeling that Rust is not just a new fork of C or C++. There is a lot to learn about Rust and the program is not just another C version. Rust isn’t for every programmer. It certainly appears to have its place. It doesn’t make sense to use Rust for a general use business application. .Net, Java or some other higher-level program would make more sense for these apps. When you need to get down into the weeds, small file size, small memory, fast processing then Rust might be the answer. The Rust Programming Language book is the first step to start to learn this new up and coming language.

Have a book that is a must read? Drop me a comment or email and give me a suggestion of books to add to the pile!

Leave a Reply