Considering the number of programmers using C, it is a language poorly served by technical books (on my bookshelves I have more than 10× as many C++ books as C ones). I think that a lot of people consider C an easy language to learn and just learn some basics and start coding. I’ve also seen a lot of spaghetti C code that makes me think that just being able to write a
for loop doesn’t count as a qualification to write a large software package.
All that to say that I feel that there is a strong need for more books like this. Despite the title pun, this book is about low level or implementation design patterns. There are 50 or so patterns described in the book split over 9 chapters and ending with 2 chapters describing how all of the patterns could be put together in larger subsystems (a logger and a user management system).
The chapters cover Errors, Function Input/Output, Runtime Flexibility and Physical Design. Each of the Patterns follows a common layout: sections titled Context, Problem, Solution, Consequences, Known Uses and an Example. There are too many things to list in detail so I’ll just select a couple at random.
‘Special Return Values’ is one of several patterns covering error handling. Since C has neither exceptions not structured bindings it is limited to either a single return type (possibly aggregate) or output reference arguments (or some global value). This pattern covers the case where you don’t want to return an error code like an enum, so instead return some special value indicating an error, like
‘Cursor Iterator’ describes abstractions that allow you to traverse containers independently of the underlying data structures. Such abstractions can also isolate the Iterator from invalidation should the underlying data be modified. Lastly, the Iterator interface can be made thread-safe.
On the whole I found the contents to be fairly sensible and to cover a fairly large spectrum of C programming. A few times I wondered why people want to recreate C++ features in C - why not just use C++ since compatibility with C is a C++ design goal.
There are a few things missing in my opinion. There are 2 chapters on Errors, but nothing on testing. I quite like data-driven design, and there’s none in this book, just some discussion about choosing where to put your data (global/static, stack or heap). Personally I wouldn’t recommend the Lazy Cleanup pattern other than for trivial applications (solving the resource cleanup problem by not doing any and letting the OS release resources). One last little niggle. I didn’t particularly like the pseudo-hand-drawn style of the diagrams.
So to summarize. I enjoyed the book and it’s well written. I think that it does a good job of doing what it sets out to do. However, sadly, I fear that the vast majority of people that would benefit from this book won’t read it and will continue churning out spaghetti.