TechBookReport logo

Keywords: Refactoring, open source, understanding code, software maintenance, Java, C

Title: Code Reading

Author: Diomidi Spinellis

Publisher: Addison Wesley

ISBN: 0201799405

Media: Book, CD

Level: Intermediate/advance programmer

Verdict: An interesting read, with some useful tips and techniques

According to Joel Spolsky, the single greatest development sin a software company can commit is to completely rewrite an existing product from scratch (quoted in Merrill R Chapman's In Search of Stupidity). And why would any company with a grain of good sense do something so fundamental? Because for programmers: it's harder to read code than to write.

Whether you agree that rewriting an existing product from scratch is sin number one or not, there's no denying that Spolsky is dead right about the difficulty of reading code. There isn't a programmer alive who hasn't had the experience of being handed somebody else's code and being told 'fix it'. Your heart sinks, you mood drops and it only gets worse when you start looking for supporting documentation (whaddya it's my own code - I wrote it months ago!).

The maintenance cycle doesn't go away, and as software gets older the burden of keeping old code alive and functioning is increasing all the time. We learn a language through reading and writing, but when it comes to software we learn mainly through writing. It's for this reason that Diomidis Spinellis has written the first book ever on the topic of Code Reading.

As well as providing a detailed introduction to the subject, a key aim of the book is to provide practical advice for the developer. While there are a core of techniques which are independent of programming language, there are also sections of the book which look specifically at data structures and coding standards from a specific language perspective. There are also two complete chapters that look at C data types and structures. Additionally the use of build tools, including make files, is also discussed in some detail.

Code reading involves more than scanning lines of source, there are skills in analysing the use of data structures, global variables, understanding coding conventions, directory structures etc. In terms of tools the book looks at the familiar tools of a developers trade - including editors, search tools, CVS, compilers etc - and how they can help in navigating and understanding complex code. Basically, any tool that helps you write software can also be used to help you read code, and Spinellis aims to show you how.

While there is an open source flavour to the book, the techniques on offer apply to all forms of code, irrespective of licence type or philosophy. The accompanying CD, however, is packed with open source code (44,000 files running to 7 million lines of code), including the code for Apache, NetBSD, the Perl language, the hsqldb Java relational database engine and more.

The final part of the book is also one of the most instructive. A complete worked example is shown, with the author making a change to the hsqldb engine. The techniques that have been piloted throughout the book are used to good effect.

Whether you are actively engaged in refactoring code, stuck in a maintenance cycle or picking up a piece of an open source project for the first time, this is a book worth reading.

Hit the 'back' key in your browser to return to subject index page

Return to home page