linux and windows tips, mathematics, and some recipes

Sunday, April 09, 2006

Reviews: Kernighan and Pike, The UNIX Programming Environment

A real classic of its genre, this is the first book ever written on UNIX, published in 1984 and still in print today. While some of the details may have changed, the book remains relevant by expounding timeless principles of good programming practice.

The authors are true gods in the pantheon of computer science. They worked together at Bell Labs in the early days of UNIX and have since been instrumental in the development of computing. Rob Pike co-developed UTF-8 with Ken Thompson and now works at Google. Brian Kernighan[1] co-wrote The C Programming Language with Dennis Ritchie, a book widely regarded as the bible of C. Kernighan is now a professor at Princeton University.

The wit and sagacity of these men is evident in their book. Each new idea is fully reasoned out and they take delight in presenting novel solutions with the minimum of raw material. My favourite example is their 'bundle' shell script from Chapter 3. This is a 10-line program which creates self-extracting archives by using the principle of 'here documents'.

In content, the book is split into two parts. The first four chapters deal with the details of using UNIX: simple commands, the file system, interacting with the shell, pipes, redirection, and a little on awk, grep, and sed. Chapters 5 through 9 are more directly concerned with programming. In particular, shell programming is covered in Chapter 5, culminating in the development of a version control system! Chapters 6 and 7 discuss the stdio library and UNIX system calls. Chapter 8 brings it all together with the implementation of 'hoc', a programmable calculator. Kernighan and Pike take the time to develop it organically, building up hoc from a simple four-function calculator. This chapter introduces the yacc parser generator and the lex lexical analyzer generator. As a matter of historical interest, document preparation using troff is discussed in Chapter 9 — this system is used to create UNIX manual pages.

The only real drawback of this 20 year old book is that some of the examples don't work correctly, or are irrelevant. It is unlikely that you will use the 'mail' command to read your mail, or the 'ed' editor to write your documents. Running 'od -cb .' no longer prints out the contents of the directory-as-a-file. However, these are minor issues. Learning 'ed' is a good introduction to regular expressions, and you may have occassion to use 'mail' in a shell script!

If you only buy one book on the UNIX programming environment this summer, make it this one.

[1] the 'g' is silent


Post a Comment

<< Home