The Art of UNIX Programming

Eric S. Raymond

Addison-Wesley 2004
A book review by Danny Yee © 2003
In The Art of UNIX Programming Eric Raymond covers programming in the broadest sense: not just engineering aspects of design and implementation, but also Unix philosophy, history and culture, and the social aspects of development in an open source world. Covering so much, it is necessarily shallow, but that also makes it easy reading — and entry points are provided for those wanting more. There are plenty of case studies and examples, and the emphasis is on practice rather than abstract theory.

Raymond begins with Unix philosophy, with what Unix gets right and some of its "rules". He gives a brief history of Unix, covering its origins and its fusion with early Internet culture and the free software movement, culminating in "open source". And he contrasts the Unix approach with alternatives, considering alternative approaches to multitasking, boundaries, file formats, interfaces, etc. and then specific other operating systems such as MacOS, VMS, OS/2, and Windows NT.

Turning to design, he starts with modularity and the concepts of compactness, orthogonality, and "single point of truth". The Unix emphasis on textuality is illustrated with examples ranging from /etc/passwd to data-file metaformats (RFC 822, XML), application protocols (SMTP, POP3, IMAP), and metaformats (HTTP, SOAP). This is followed by a more general look at Unix approaches to designing for transparency and discoverability.

A chapter on multiprogramming offers a taxonomy of Unix IPC methods: "shelling out", pipes and filters, wrappers, Bernstein chaining, and slave processes and peer-to-peer communication using tempfiles, signals, sockets, or shared memory. Problematic methods include Sys V IPC, RPC and threads.

Raymond considers twelve examples of "minilanguages", ranging from regular expressions and the simple declarative languages used in data files to Javascript and Emacs Lisp, and offers tips on designing new ones. And a brief chapter covers data-driven programming and ad-hoc code generation.

Raymond explains the various ways Unix does program configuration — run control files, environment variables, command line options — again with case studies. On interfaces he runs through some common Unix designs: filters, return value only "cantrips", sources, sinks, compilers, ed-like (line), roguelike (curses), various kinds of engine/interface pairs, and network servers. The Rule of Least Surprise and the "Silence is Golden" principle (no unnecessary output) also get a mention.

A chapter on optimization — "a very short chapter, because the main thing Unix experience teaches us about optimizing for performance is how to know when not to do it" — is followed by one on complexity. Here Raymond considers ed, vi, sam, Emacs, and wily as examples, and asks "Is Emacs an argument against the Unix tradition?" — he suggests that Emacs is best considered a framework rather than a tool.

Moving on to "Implementation", Raymond begins with the special place of C under Unix; he then offers evaluations of 8 languages and advice on choosing an X toolkit. A quick tour of major Unix programming tools covers vi or emacs, yacc and lex, make, version-control and profiling tools, and emacs as an IDE. And a chapter on reuse focuses on the advantages open source offers; it is here Raymond discusses open source licensing issues from the point of the user.

The final section covers "Community". Here Raymond looks at the evolution of C and Unix standards, the IETF and the RFC standards process, programming for portability, and internationalization. He surveys the messy "zoo" of Unix documentation formats — troff, TeX, Texinfo, PD, HTML, ... — with a detailed look at DocBook and associated tools as "a possible way out". And he outlines "best practice" in open source collaboration with other developers, and explains the logic of open sources licenses and how to pick one for your own project.

A final chapter considers opportunities and risks — problems in the design of Unix, and possibly in its environment and culture — and looks at Plan 9 as "The Way the Future Was".

Raymond writes clearly and effectively, and is prepared to make strong statements using informal language, sometimes humorously.

"The combination of threads, remote-procedure-call interfaces, and heavyweight object-oriented design is especially dangerous. Used sparingly and tastefully, any of these techniques can be valuable — but if you are ever invited onto a project that is supposed to feature all three, fleeing in terror might well be an appropriate reaction."
The text is sprinkled with Zen references and an appendix offers some Unix koans — it seems the originally intended title was "The Tao of Unix Programing"; there are some set piece stories, such as the "Tale of J. Random Newbie". The result is just plain fun.

A notable feature of The Art of UNIX Programming is its use of many small case studies, some of which I found informative in their own right — I didn't know about SNG, the textualised PNG format, for example. Raymond draws on his own experience for many of his examples, with fetchmail featuring several times (though CML doesn't get a mention). A nice inclusion is the occasional brief comment on the text by Unix pioneers such as Brian Kernighan and Doug McIlroy, chipping in with a personal perspective.

Raymond's politics hardly intrude at all — gun rights sayings as fortune file examples is about it. The only thing that jarred for me was a triumphalist declaration of victory for "open source" over "free software".

For most hackers and almost all nonhackers, "Free software because it works better" easily trumped "Free software because all software should be free".
Most hackers may not support the explicitly political agenda of the Free Software Foundation, but it is still freedom which is central to their attraction to free software — freedom from dependency on vendors, freedom to innovate and share innovations — with purely engineering advantages concomitant on that. And most nonhackers don't understand or care about the "works better" arguments at all — here "free as in beer" is possibly the biggest selling point, though the political angle seems increasingly important in some countries.

Anyone doing Unix programming should find plenty to chew on in The Art of UNIX Programming: even experienced Unix hackers may learn a few new things from it, or perhaps have fun finding things to disagree with. Programmers from outside the tradition wanting an introduction should also find it rewarding. The only real requirement is some interest in programming, even if it's only (as in my case) the occasional programming ventures of a system administrator. The full text is available online, but The Art of UNIX Programming is designed for reading rather than as a reference, so a print copy is in my opinion well worth having.

This review is dedicated to the memory of David Hogan, Unix and Plan 9 hacker.

December 2003

External links:
- buy from or
- information from Eric S. Raymond
Related reviews:
- Eric S. Raymond - The Cathedral and the Bazaar: Musings on Linux and Open Source by an Accidental Revolutionary
- books about computing
- books published by Addison-Wesley
%T The Art of UNIX Programming
%A Raymond, Eric S.
%I Addison-Wesley
%D 2004
%O paperback, index
%G ISBN 0131429019
%P 525pp