“Code Reading: An Open Source Perspective“, by Diomidis Spinellis, is a new kind of book. It’s a foray into a domain normally left untouched by Computer Science texts and exemplifies yet another positive contribution from the Open Source movement. Simply put, Code Reading is a detailed discussion of the techniques required to read and maintain both good and bad code. As an interesting twist, the author draws on projects from the Open Source world to provide examples, both good and bad.Presentation
The book is approximately 400 pages long, and well packed with information. I found the text to be perfectly readable, if occasionally a bit terse. I wonder if perhaps this might have been rectified by splitting the book into two volumes, but then again as the first such book of its kind it would have been harder to gain acceptance in a multi-volume format. Source code is presented throughout the work, both in raw and diagrammed forms. Just by opening to a random page one can be assured of finding at least one source example, if not more. One of my favorite features is that this book, unlike many others, is not reserved about re-printing the same text. If the author has discussed some new method of analyzing an example, the example will be reprinted with the appropriate highlighting to mark the author’s point. This is a pleasant relief from any number of other books the expect the reader to picture the author’s discussion mentally.
The book is broken down into logical chapters, separating language independent notes from those dependent on the C language family. There are also handy indices of both code examples and tables, useful when you’re trying to find an example of that one construct you remember reading about. For those who might be using this in a classroom setting, there is a list of “maxims,” organized by chapter, in the appendices, as well as a thorough bibliography for those wanting to delve deeper. Also, every section features “Exercises” which provide suggested further studies and areas of code to look at. For instance, the section on test cases suggests using the “execve” regression tests (included on the CD) to derive the error codes provided in the man page. All in all, the book is thoughtfully organized for easy reference and study.
Source Code
Source used in this book is drawn from across the Open Source world, though almost exclusively from projects using BSD-style licenses. While this is never said explicitly, I suspect the author wanted to be careful of possible licensing problems involving the more strict GPL, but nonetheless he has done an excellent job finding projects to suit his examples: projects such as Apache HTTPD & Cocoon, NetBSD, Perl, and XFree86 make appearances in the book, along with other smaller projects. Every project’s license is printed in the appendices, along with a small blurb describing each one. There is also a separate page crediting all the copyright-holders of the example code.
This book is not, however, for those looking to gain deeper insight into these specific projects. The examples are extremely localized and taken out of context. While the file name where each example occurs is given in the footnotes, only as much context is given as is needed to analyze the function of the snippet. In addition, all of the code used in the book is intentionally taken from older snapshots of the projects, so as to allow the author to point out now-discovered bugs, and to present the manner in which they were fixed. While this may disappoint those wanting to know just how Apache works, it provides useful examples on common bugs. In addition, all of the code used in the book is provided on a CD-ROM, for easy browsing.
Conclusions
In all, Code Reading is a successful beginning for a genre of technical writing that I hope will become more popular. It harks back to Lions’ Commentary on Unix, but in a more structured format. It shows yet again that Open Source can be used to fill another of the major gaps in the computing world, albeit in different manner than anyone originally intended.
The book is well written, and my only complaint is that at times the explanations can be a little terse, requiring repeated reading to fully understand it. I suspect this is due in part to limitations on the length of the book. I hope that future works on the subject will be able to expand on the places where information is limited in this.
My only other complaint is this book’s C-family centrism, focusing on C, C++, and Java. This is not in and of itself a bad thing, as most of the code written now is in these languages. I would, however, have liked to have seen some (even brief) discussion of other language families and how they relate to the maxims presented in the book.
In conclusion, I would recommend this book to anyone looking to become involved in the Open Source movement, as a good appreciation for the reading of code will be of immense value. Even more than that, I would recommend it to Computer Science students and professors, as it formalizes a skill that really ought to be taught in schools.
Buy Code Reading: An Open Source Perspective
About The Author
Owen Anderson is an undergraduate Computer Science student. He studies algorithms and advanced logic, and is also interested in databases. He uses Windows XP and Mac OS X Panther on his desktop computers, and administers a Gentoo Linux server. He considers himself proficient in C, Objective-C, and Java, with dabblings in all kinds of other things.
Thanks for the review, and for simply bringing this book to my attention. I am trying to become a programmer, and I’m finding that reading code is the most difficult thing to pick up — much harder and slower than writing it. I find that once I’ve thought a problem through, implementing a solution is fairly quick; but understanding what someone else’s program is doing takes much more time. And reading code is not covered in the classroom at all(not yet for me, at any rate). I may have to pick up a copy of this book.
My questions to the reviewer are: 1) How much did the book do for you from a practical standpoint? Do you find it easier/faster reading code now that you’ve read it? 2) What level of experience do you think the book requires to be useful?
You can gain such a rich insight into the computer cultural biases and heritage of a programmer by looking at the idioms, conventions, and structure of her source code. I’d be interested to know if this book discusses the cultural histories of programming style at all?
-braddock
1) I haven’t had a chance to try it out reading a large chunk of code, but I have found my style of writing to have improved. I was working on a Java Servlet a little bit after I finished reading it, and found myself thinking about how to clarify my style, and where were good points to put in comments. All in all, I think it had quite a good effect on my coding style.
2) While it does provide brief explanations of most C features, this is not a Learning C book. At least an intermediate knowledge of C is require, and some experience with C++ and/or Java would be helpful. But the most important thing is a working knowledge of C-style syntax.
Thanks all, and happy Thanksgiving!
I do C from 1990, I have always liked NetBSD.
Thanks Owen for reviewing that book.
I’m going to a buy a copy.
Thanks again!
Reviewer:
“My only other complaint is this book’s C-family centrism, focusing on C, C++, and Java”
The book briefly mentions that there is going to be a volume two which will have scripting languages covered. This book is great, maybe one of the best books I’ve read on programming, I’m eagerly awaiting vol. 2.
This is probably going to start a flame war……but here goes….
I come from the philosophy that if you understand C,C++ porting syntax to another language is straight forward.
Scripting languages especially (I’m thinking PERL, Python etc.), if you jump right into these languages, learning them is cool…..but then moving onto C, you’re in for another steep learning curve.
Learning C/C++, and then switching to Python/Perl seems to be such an easier transfer of knowledge.
I love Python (and some other script languages) for its quick application development, but I think I understand why this book is focussed on C…..it is probably the most widely used to app development, and once you get C/C++ style down, you can transfer it to other languages fairly simply.
I come from the philosophy that if you understand C,C++ porting syntax to another language is straight forward.
True for block-like languages, like the most popular (Pascal, Java, Python, Perl, Ruby, PHP, Lua, etc.) are nowadays. Not true for Lisp, Haskell or Prolog, for example.
Your comment that most programming is done in C or any of the other Algol family of languages is a bit off the mark. This assumption is relevant only in the open source community. There is upwards of a billion lines of COBOL code generated every year in the financial sector alone. The aerospace community is Ada centric and there is a lot of legacy code that remains (and will continue for a long time) in Fortran. In my opinion Steve McConnell’s book “Code Complete” still remains a classic particularly because of his insistence on not focussing on one particular language.
All the code samples do come from NetBSD because the publisher was comfortable with that license. (This was in the preface).
I think it’s good to be familiar with programming idioms. That’s what I’ve got out of the book so far.
Will this help a novice.
I have read K&R and Practical C.
I tried to read c unleashed.
Not all of the examples are from NetBSD, a few are from a Java program (something to do with Apache) and Apache itself. He did choose BSD licenses because of the publisher perhaps, but the author is a FreeBSD committer so he likes BSD.
This book starts out on a very easy level, it should be fine for anyone who’s semi-literate at C, at least for the first few sections of the book. In fact it should improve your ability to write code as well as read it due to this coverage of basic coding structures and practice.
>> The aerospace community is Ada centric…
Not true. The aerospace community is Fortran centric.
Tom H.
Aerospace Engineer
I’ve used several programming languages over the years but the only one I’ve ever HATED is COBOL. Aside from it’s installed base, are there any good reasons to keep using it?
Damn fat fingers. Hey, how about a preview mode, guys?