May 5, 2013

The Practice of Programming (book review)

I don't need to introduce authors Brian W. Kernighan or Rob Pike. The authors were one of the reasons why I bought this book. It was published in 1999. Although it's a bit dated, but still relevant to this day. The book consists of 8 chapters. Each chapter is divided into suchapters and many have small paragraphs with different focuses. I'll keep it short not to spoil the book.

1. chapter - Style
key words: names , style consistency, macros, magic numbers, comments.
Be consistent in your code, use indent to show structure, use descriptive names for globals, don't leave comment for obvious code.

2. chapter - Algorithms and Data Structures
key words: searching - linear , binary searching, sorting - Quicksort, O-notation, Trees, Hash tables, Lists
This chapter serves as an introduction to a searching, a sorting and data structures.

3. chapter - Design and Implementation
key words: markov chain algorithm
Implementation of markov chain algorithm in C, C++, Java, Awk and Perl. They measure performance and show differences in the implementations.

4. chapter - Interfaces
key words: comma separated values
An implementation of CVS library in C and C++. What is discussed in this chapter : How to create an interface, error handling, resource management, implementation details.

5. chapter - Debugging
key words: bug, debugger, tracing
How to solve a bug, don't make the same mistake twice, stack trace and many more tips.

6. chapter - Testing
key words: white box testing, black box testing, scaffolds
Test bondaries, pre/post conditions, error returns, test scaffold, test coverage.

7. chapter - Performance
key words: efficiency, profiling
They used spam filter as an example to show how to improve performance. Few versions of spam filter is presented with their performance issues. There are advices how to tune the code.

8. chapter - Portability
key words: standard, undefined behavior, C libraries
Typical problems are presented like signess of char, byte order, shifts, bitfields and many more.

9. chapter - Notation
key words: regular expressions
How data are formatted (an example of creating a packet for sending). Regular expressions with grep, awk, tcl and perl examples.

Each chapters contains Supplementary reading which provides more sources. There are exercises in the end of many sub chapters. 

One addition which is from the last year from Rob Pike: http://www.informit.com/articles/article.aspx?p=1941206 . 
Thinking debugging is much more powerful than line-by-line debugging. I tend most of times to think first before I debug but I need more experience to do it quick and right the first time.

What I enjoyed, was real examples from their experience or others.

References: