Introduction
One day, I got an email in my mailbox. It was from Aaron Hillegass, asking me to review his and Mark Dalrymple’s new book, ‘Core Mac OS X and Unix Programming: Master Darwin and the Core Technologies’. I reviewed Aaron’s last book on Cocoa Programming, ‘Cocoa Programming for Mac OS X’, and I must have pleased the author (the book sure pleased me!).
However, as I grasped what ‘Master Darwin’ was about, I silently smiled to myself thinking that poor Hillegass had made the mistake of his life, asking me to review a book on Unix programming. Given that I’ve never gotten beyond mkdir, ls, top, and uptime as far as Unix goes, he could as well have given John Milton’s ‘Paradise Lost’ to a six-year old. But I was wrong. Aaron and Mark made a better programmer, and somewhat of a Darwin acolyte, out of me, the same way Aaron had turned me into a Cocoa programmer a few months ago (now, if Big Nerd Ranch would only release an OpenGL book).
Besides giving a Unix book to someone who finds KDE to be arcane, the timing couldn’t have been worse. The package arrived while I was in the middle of changing apartments and had a game programming deadline one month down the line, not to mention having started to work full-time a week earlier. So, I took the book to work, and I read it on the subway. Much like the Cocoa book, I was hooked rather quickly.
Meanwhile, Back at the Ranch
The book originated from Big Nerd Ranch’s course, and is essentially the student guide for those who attended it. It starts out with a well written, albeit a bit short, introduction to Unix and an explanation of where Mac OS met Unix. I might be thick, but it wasn’t until here that I finally grasped what Darwin was all about. Following that is a very good C refresher. I tend to skip these, but this one is very informative. For me, it was not just a refresher, but a source of both some new material that I have never gotten around to researching, and of reassurance regarding certain things I had only suspected. All the neat-o code tricks with which most books seem to be riddled and that clutter the examples (a manifestation of the author’s ego?) are stuck in the refresher. Every code example through this book is clean and easy to read.
‘Master Darwin’ contains both Objective-C (with Cocoa) and straight C. Is there an Obj-C refresher? Unfortunately there is not, but Aaron’s ‘Cocoa Programming for Mac OS X’ covers that in detail. Considering the excellence of this refresher, as well as the use of Objective-C, it shouldn’t have been too much work to just throw in a quick five-page explanation of basic Obj-C concepts (but then again, this isn’t a language textbook). This book contains no C++, but for once, this is positive. Nothing in the book is dependent on C++, and nothing in it excludes C++. All objective-oriented concepts are introduced through Cocoa and Objective-C. No, this is not a book on languages. It’s a book about a killer platform, and, to my relief, Aaron and Mark have made that distinction very clear, and stuck to it. The text is devoid of any “code knowledge” (outside the C Refresher), which makes it effective. I’m impressed with their discipline. In all, the book is very clean and to the point.
New Book in Town
Throughout ‘Master Darwin’ the authors make the line betweek Unix and Mac OS X very clear, and this is an important point. For those like me who are unfamiliar with Unix, it gives confidence to know where a particular concept originated from, and what it is related to. As teachers, the authors are very reliable. They explain what’s hard and why it is hard, which is something that I always appreciate. Also, they offer not only knowledge, but experience, and experience from one Unix guru and one former NeXT employee is the best kind with which to write this book. If you want to learn some Unix on your Mac, then they’ll give you that on the fly, too.
The topics range from mouthwatering headlines such as “Network Programming With Sockets”, “Multiprocessing”, “Rendezvous”, “Multithreading”, and “Performance Tuning”, to some more low-key things that you didn’t know you needed: a very meaty and useful walk-through on the GCC compiler, debugging with GDB (and boy, did this make my debugging more effective! That chapter alone was worth reading the book for), File I/O, and a very interesting chapter on memory handling.
A few of these chapters deserve a closer look. The three chapters on the compiler, how to build different types of libraries, and handling command line programs build a very stable knowledge and confidence regarding how to actually use the tools that hang around the developer tools. These chapters are an explanation of a lot of different tools that I have found use for, especially when it comes to debugging and building libraries. Project Builder looks a lot more attractive when you know what’s beneath the surface. Together with the GDB (GNU Debugger) chapter, I feel like a god.
The chapter on memory does a great job of explaining the Unix memory model and how it relates to the old Mac OS memory model, as well as the different memory allocation calls, problems and pitfalls, and memory debugging methods. Learning how to set the memory debug environment variables is downright invaluable. In fact, the first nine chapters give a very solid understanding of the entire platform and the tools.
The chapter on multithreading is quite easy to grasp, especially if you’ve worked through the chapter on multiprocessing first. I read them in reverse order, but despite that, I managed to get a simple multithreaded application up and running in no time. However, the multithreading chapter is placed a little too late in the book in my opinion. Several of the earlier chapters refer to it and talk about possible problems with threading, before one has even got a grasp on what threading involves. On the other hand, if one were to reorder the chapters, the threading chapter would be among the first ones, and that would look rather silly (not to mention scaring readers away). Just make sure that you skim that chapter early on if you plan to do multithreading, to get an idea of what it’s all about.
A very useful chapter lives near the end of the book. It is the one on CVS, which is a tool (type ‘man cvsin’ the Terminal to get a quick look) to handle source files in larger projects, especially when there are multiple persons working on them. As someone who works on two machines (a tower and a laptop, not to mention that I’ve become rabid about backing up data after a few mishaps involving a Powerbook and a hammer), CVS will be with me from now on. Still, that chapter exemplifies a small weakness in many of the walk-throughs in this book — in a few places (not many, maybe three or four in five hundred pages) the instructions are ambigous. Asking the reader to “cd somewhere” isn’t much help, if the previous text has worked with three different directories.
However, despite the threading chapter placement, ‘Master Darwin’ is better planned than Aaron’s Cocoa book. First there are a few “getting started” chapters, and then an assortment of rather independent lesson-style tutorial chapters. Actually, the book feels very much like a cookbook, with a few chapters in the beginning describing the tools and their use, and then mouth-watering recipies. Even the “For the More Curious” sections would feel very well-placed in a cook book, as well as “More Advanced Issues”. One little discomfort is the lack of page references. I always prefer “…on page 152” rather than “…later in the book” or “…discussed elsewhere”.
It’s evident that this is the student literature for Big Nerd Ranch’s course. As such, it works very well; I picked up the book, jumped into the middle of it, typed in and compiled the example programs, and I could solve the challenge at the end of the chapter. That’s a good mark for any book. All the code in the book is, as I said, very easy to read and structured. Read Bjarne Stroustrup’s official book on C++ — that code looks like it was obfuscated on purpose! But in ‘Master Darwin’, they are not only well-written, they are good too! They examine and exercise every aspect of the concept they illustrate, and do so in concise manner. When the authors examine sockets, the example programs wade through writing a simple network server and a simple client for that server in less than four pages, and yes, that is quite remarkable. In short, these are the best code examples I’ve read.
Into the Sunset
After reviewing Aaron’s Cocoa book, I looked at other reviews of it. It seemed like reviewers couldn’t decide on whether or not they liked the fact that the chapters consecutively built upon one another. Some people like to be able to jump in into the middle of the book and start from there, others like it when a book gives a well-knit reading experience. The duality of the two formats is resolved nicely here. For those who like to jump in and just do a few exercises, feel free. I did this, because I was interested in threading, and it worked out fine. For those who like to read the book like a textbook, do so. Keep on reading and coding from page 1 to 532, and you’ll notice how nicely everything ties in with the multichapter applications.
Above that, the book has a very nice layout. I really like when the important parts of a code example are put in bold face, as I am not too fond of reading code.
Who should get this book, then? Is this the ultimate book? Well, it might be the ultimate book for you. It clearly isn’t a beginner book, nor is it for anyone who already knows their Unix. In that sense, it is a book for the advanced, as opposed to the super-users. I suggest that you know your way around C and Cocoa (and subsequently Objective-C) before picking up this book. And no, it is not only for application programmers. Game programmers can benefit greatly from many of the chapters, something that I had never expected from this title. However, the greatest thing about this book is that it imparts confidence. If you code a few code examples from the book, you’ll soon notice that the first example in each chapter is rather complex, or at least not the simplest possible. That way, the authors give you proof that “you can do this”, and then they go about explaining things more in-depth. This is much similar to Aaron’s Cocoa book, which was quite ripe with “you can do this” pep talk. Finally, yet another reason to get ‘Master Darwin’ is that it’s a very good book to improve your C skills. It’s not a book on abstract programming principles, but a high-mark book concerning hands-on programming.
In short, this is a book to read in bed, as it is written in a very readable way. Put it under your pillow, remember what topics it covers, and then whip it out when the time is ripe (it will be ripe sooner than you think). The bottom line: this is an extremely useful book, not only packed with interesting information, but also well-written. I can’t wait for Mac OS 9 to die.
Related Links: