Slashdot is powered by your submissions, so send in your scoop

 



Forgot your password?
typodupeerror
×

The Art of Unix Programming 358

rjnagle writes "Eric S. Raymond (or ESR) is widely known for the groundbreaking series of essays in his book, The Cathedral and the Bazaar. In TCatB, he makes a credible case for why open source sofware works so well, and why community-supported software won't put developers out of a job. (I once attended a delightful talk he gave where, among other things, he gave sartorial advice to open source developers, urging them to avoid formal suits at presentations to CEO's as a way to give off the auras of foreign dignitaries unused to local customs). The arguments presented in Cathedral and the Bazaar were persuasive and original and now regarded as obvious. In his new book, Art of Unix Programming (available for free on the web), ESR stakes an even bolder claim: that initial design decisions make Unix uniquely well-suited to take advantage of open source's power. This book is an attempt to explain why Unix is so...well, Unixy." Read on for the rest of Nagle's review of The Art of Unix Programming.
The Art of Unix Programming
author Eric S. Raymond
pages 560
publisher Addison Wesley
rating great and free on the web!
reviewer Robert Nagle
ISBN 0131429019
summary Instructive for the Student; Profound for the Professional

On the surface, this book is a gentle introduction to programming; but in reality it is an attempt to explain the Unix aesthetic; at times I felt as if I were reading less a technical guide than an art history book, a chatty account of Gothic Architecture as told by someone who helped build a few churches himself. ESR articulates a set of design principles for Unix, which because of succintness deserve reprinting here.

  1. Rule of Modularity: Write Simple Parts connected by clean interfaces.
  2. Rule of Clarity: Clarity is better than cleverness.
  3. Rule of Separation: Separate policy from mechanism; separate interfaces from engines.
  4. Rule of Simplicity: Design for simplicity; add complexity only where you must
  5. Rule of Parsimony: Write a big program only when it is clear by demonstration that nothing else will do.
  6. Rule of Transparency: Design for visibility to make inspection and debugging easier.
  7. Rule Of Robustness: Robustness is the child of transparency and simplicity.
  8. Rule of Representation: Fold Knowledge into data, so program logic can be stupid and robust.
  9. Rule of Least Surprise: In interface design, always do the least surprising thing.
  10. Rule of Silence: When a program has nothing surprising to say, it should say nothing.
  11. Rule of Repair: Repair what you can--but when you must fail, fail noisily and as soon as possible.
  12. Rule of Economy: Programmer time is expensive; conserve it in preference to machine time.
  13. Rule of Generation: Avoid hand-hacking; write programs to write programs when you can.
  14. Rule of Optimization: Prototype before polishing. Get it working before you optimize it.
  15. Rule of Diversity: Distrust all claims for one true way.
  16. Rule of Extensibility: Design for the future, because it will be here sooner than you think.

ESR shows how to follow these general principles while writing Unix programs. The central metaphors of Unix (that everything is a file, and data-streams that can be piped and redirected) are intuitive, and maximize transparency and separation. About pipes, he writes:

A subtle but important property of pipes and the other classic Unix IPC (Interprocess Communication) is that they require communication between programs to be held down to a level of simplicity that encourages separation of function. Conversely, the result of having no equivalent of the pipe is that programs can only be designed to cooperate by building in full knowledge of each others' internals (p 81, Chapter 3)

Interestingly, the real opposing aesthetic to the Unix aesthetic is not Microsoft (which really is a hybrid), but Macintosh:

The Macintosh's unifying idea is so strong that most of the other design choices we discussed above are either forced by it or invisible. All programs have GUIs. There is no CLI at all. Scripting facilities are present but much less commonly used than under Unix; many Mac programmers never learn them. Mac OS's captive-interface GUI metaphor (organized around a single main event loop) leads to a weak scheduler without presumption... Mac OS applications are not, however, invariably monster monoliths. The system's GUI support code, which is partly implemented in a ROM shipped with the hardware, and partly implemented in shared libraries, communicates with Mac OS programs through an event interface that has been quite stable since its beginnings. Thus, the design of the operating system encourages a relatively clean separation between application engine and GUI interfaces.

ESR's criticism right here (and throughout the book) is not necessarily condemnation. In fact, ESR recognizes that Macintosh as a competing aesthetic has a lot to offer that Unix does not. For example, Mac file attributes (in which a file has both data and resource "forks") provide mechanism for richer GUI support. Thus, we have (ESR says) developers "who work from the interface inward, rather than the engineer outward." In contrast, the Unix byte-stream metaphor may make it hard to conceptualize the meaning of operations such as Create, Open, Read, Write and Delete.

With Unix, the Rule of Least Surprise suggests that the developer delegate interface functions to a GUI or to another program. Instead of creating a built-in editor inside an application, the developer should allow the user to choose which editor to use. Instead of making a robust and easy-to-use interface, the Unix developer should produce a command line utility first, and then let someone else create a separate and independent GUI layer. (Rule of Separation). Xcdroast is a perfect example of a GUI layer for the command line program, cdrecord.

The Command Line Interface (CLI) may scare off new users, but it offers endless scripting and batching capabilities for programs (and smooth IPC). Also, it offers expressiveness to developers. "The Unix programmer," ESR writes, "is likely to see defaulting away from expressiveness as a sort of cop-out or even betrayal of future users, who will know their own requirements better than the present implementer. Ironically, though the Unix attitude is often construed as a sort of programmer arrogance, it is actually a form of humility -- one often acquired along with years of battle scars" (p.304, "Interfaces,")

ESR distinguishes between interface complexity and implementation complexity. Unix projects often involve tradeoffs on these two. The Unix developer prefers a lean and simple implementation at the expense of a usable interface; ESR writes:

Programs that mediate between the user and the rest of the universe notoriously attract features. This includes not just editors but Web browsers, mail and newsgroup readers, and other communication programs. All tend to evolve in accordance with the Law of Software Envelopment, aka Zawinski's Law. 'Every program attempts to expand until it can read mail. Those programs which cannot so expand are replaced by ones that can'".

The book devotes considerable space to showcasing Unix best practices (which in most cases, means readable config files, limiting the program's scope, providing access to sufficient debug information and making it easy to hack). He offers sensible advice about when to use minilanguages ("don't extend your way to it, one patch and crufty feature at a time"), why to limit the number of available command-line switches (each one increases debug time), why optimization has few payoffs ("Moore's law implies a 26% performance gain just by buying new hardware every six months") and why bottoms-up programming can work better than top down design(because "it gives you time and room to refine a vague specification" when "...you are programming in an exploratory way, trying to get a grasp on hardware or software or real-world phenomena you don't completely understand.").

One of the most instructive chapters was about J. Random Newbie, a fictional programmer fresh out of college who understands basic programming concepts and the value of reuse. ESR presents a scenario of how Newbie nonetheless ends up rewriting rather than reusing, relying more on his own code than that of others. When he changes jobs, "he is likely to discover that he can't take his toolkit with him" and may even find it to be useless at a new job with different proprietary tools, languages and libraries. Thus, ESR writes:

Programmers have reuse (and other good practices that go with it, like modularity and transparency) systematically conditioned out of them by a combination of technical problems, intellectual-property barriers, politics and personal ego needs. Multiply J. Random Newbie by a hundred thousand, age him by decades, and have him grow more cynical and more used to the system year by year. There you have the state of much of the software industry, a recipe for enormous waste of time and capital and human skill -- even
before you factor in vendors' market-control tactics, incompetent management, impossible deadlines, and all the other pressures that make doing good work difficult. (p.420, "Reuse")

This book is a good introduction for this newbie programmer (as well as a warning about what to expect). It offers practical advice about which license and language to use, how to set up documentation, how to decipher the standards process, how to check things into CVS and how to submit a patch to an open source project.

The chapter on Unix's history puts the current SCO/IBM controversy into perspective. Unix has always been dogged by exertions of commercial control, and ESR accurately conveys how the software world is constantly swinging back and forth from periods of intensely-creative free-spirited openness to periods of commercial control.

I was struck by several of ESR's observations: that Linus Torvald's "refusal to be a zealot" was a contributing reason why Linux was able to succeed; that both the patch utility and email probably did more to advance the Open Source movement than mere "consciousness raising."

In summary, this book is a great help for the student programmer. It synthesizes a lot of ideas and insights from other programming gurus, and is full of insights, aphorisms and fun digressions (no surprise to readers of ESR's other works). The experienced programmer, on the other hand, might find the book more profound than practical. Invoking the Zen metaphor (and even including Unix koans at the book's end), ESR shows us how the abstract nature of programming provides insight into problem-solving, design and yes, even a kind of enlightenment. The book, available for free on the Net, is probably better to read on vacation or an airplane or as a welcome break when stumped by a programming problem. More practical books on Unix programming exist (I happen to recommend Mark Sobell's), but ESR's book will stay with you long after you have finished reading, providing countless hours for reflection and appreciation of Unix's Unix-nature.


Robert Nagle (aka Idiotprogrammer), believes that plone is the best thing since garage door openers, and is a strong supporter of music sharing. You can purchase The Art of Unix Programming from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

This discussion has been archived. No new comments can be posted.

The Art of Unix Programming

Comments Filter:
  • by Eponymous Coward ( 6097 ) on Monday October 20, 2003 @01:32PM (#7261680)
    The Command Line Interface (CLI) may scare off new users, but it offers endless scripting and batching capabilities for programs (and smooth IPC).

    I think in some ways, Windows manages to out-Unix Unix. For example, I find Windows programs to be much more scriptable than their Unix counterparts.
    I'm talking mostly about OLE automation. For example, it's pretty easy to write a batch file drives any of the Office suite. Can you drive OpenOffice in a similar fashion?
    -ec

  • by duffbeer703 ( 177751 ) on Monday October 20, 2003 @01:39PM (#7261722)
    What exactly has Eric Raymond done besides write that Cathederal book or attempt to invent his own "jargon"?

    A book as high and mighty sounding as "The Art of XXX" should be written by an acknowledged luminary in the art...
  • Whatever (Score:3, Insightful)

    by Golias ( 176380 ) on Monday October 20, 2003 @01:42PM (#7261746)
    From the text of the intro: Finally (and with admitted intent to provoke) we recommend Zen Flesh, Zen Bones [Reps-Senzaki], an important collection of Zen Buddhist primary sources. References to Zen are scattered throughout this book. They are included because Zen provides a vocabulary for addressing some ideas that turn out to be very important for software design but are otherwise very difficult to hold in the mind. Readers with religious attachments are invited to consider Zen not as a religion but as a therapeutic form of mental discipline -- which, in its purest non-theistic forms, is exactly what Zen is.

    Look, I've already read "Zen and the Art of Motorcylce Maintenance" and "The Inner Game of Tennis." Do I really need another watered down screed on half-understood principals of Eastern philosophy crammed down my throat to become a better UNIX programmer? Most of the concepts that books like this borrow from Zen are so painfully obvious that it really serves as little more than padding for a poorly thought-out thesis which would only populate about 50 pages (at best) if not for the endless ramblings about holistic thinking.

    Okay, UNIX, like everything else, is all part of the Buddha. Very profound. We all marvel at your wisdom. Now stop wasting our time.

  • by Anonymous Coward on Monday October 20, 2003 @01:45PM (#7261767)
    The "ESR" is now an official unit for measuring ego. I believe it is equal to about 2 Jobs.

    I wouldn't expect to see it listed in the Jargon file any time soon, though. He's too busy filling it with warblogging terms.

    Anyway, it looks like the figure may have to be revised to be "1 ESR = 3 Jobs", since he now seems to think he's on par with Knuth when it comes to programming theory.
  • another review (Score:4, Insightful)

    by bcrowell ( 177657 ) on Monday October 20, 2003 @02:28PM (#7262091) Homepage
    Here [theassayer.org] is my own review of (an earlier version of) the book.

    In general, I have a problem with Raymond's pose as an anthropologist or sociologist of the open-source movement. Sociology and anthropology are supposed to be sciences, and scientists are supposed to try to be impartial and base things on empirical evidence, not preconceived beliefs. To me, Raymond's descriptions of the open-source culture read too much like a utopian fairy tale. The truth is that sometimes open source succeeds and sometimes it fails.

  • by schwaang ( 667808 ) on Monday October 20, 2003 @02:56PM (#7262344)
    In the section on What Unix Gets Wrong the author's prime example is how X, by striving to provide "mechanism, not policy", leaves users overwhelmed with options.
    But the cost of the mechanism-not-policy approach is that when the user can set policy, the user must set policy. Nontechnical end-users frequently find Unix's profusion of options and interface styles overwhelming and retreat to systems that at least pretend to offer them simplicity.


    I agree with this. Linux distros that hope for mass adoption add value by having a designer make the choices that put a uniform look-and-feel into the user interface (and into administration tools for that matter). Redhat, e.g., does a nice job of starting to feel like a self-consistent OS.

    However in the later comparison to NT, he knocks the registry hard for being a single-point-of-failure whereby one rogue app can corrupt the database and require a total format/reinstall. NT may be ugly by implementation, but the registry concept kicks Unix ass. (In truth it just goes the next logical step, but because it was done in Redmond and done badly at first, we think we have to reject the whole concept and keep editing a bunch of dot-files. Oops.)

    A further entry in the hate-to-admit-it dept. is the fact that Windows through COM/OLE lets different apps share data in a way that also kicks Unix butt. Hell I can't even cut and paste between most apps on my Linux box. This is another pitiful consequent of a) the extreme (& beautiful) flexibility of Unix without either b) a guiding hand (designer) to select self-consistent choices within the ones the flexibility allows or c) the humility to recognize those areas where Windows is actually better than Unix.
  • by PCM2 ( 4486 ) on Monday October 20, 2003 @03:36PM (#7262728) Homepage
    (I once attended a delightful talk he gave where, among other things, he gave sartorial advice to open source developers, urging them to avoid formal suits at presentations to CEO's as a way to give off the auras of foreign dignitaries unused to local customs).

    Buh? How is sending the message to CEOs that you don't share their values/priorities (not to mention that you have no experience in making line-item purchasing decisions, even to the extent of getting yourself a decent suit) supposed to convince them that you're worth listening to? Seems to me that they've taken the time to develop the business plans ... it's up to you to convince them how your product will fit into those plans, not that it hovers around in some everything-is-dandy fantasy land, ignorant of how 90 percent of the world does business.

    Seriously, can somebody explain his rationale on this one?

  • by El ( 94934 ) on Monday October 20, 2003 @06:42PM (#7264736)
    Mac OS's captive-interface GUI metaphor (organized around a single main event loop) leads to a weak scheduler without presumption...
    Uh, I think the phrase you're looking for is "without premption". I'll assume this was the reviewer's typo, and not ESR's original text...
  • by AJWM ( 19027 ) on Monday October 20, 2003 @11:16PM (#7266959) Homepage
    Quite correct that mkisofs and cdrecord are Unix utilities. But they are easily invoked from the command line in a script, with no additional user interaction, no GUI needed. Most Windows apps insist on opening a GUI when started, and very seldom confine themselves to just one function (ie they'll roll the functionality of both mkisofs and cdrecord -- and perhaps a few others -- into a single app).

    As ESR notes in the book, some of this is a natural result of the fact that process creation under VMS, er, Windows NT (and successors) is expensive, so programs tend to be monolithic (and occasionally internally scriptable), whereas Unix style is to separate out the functionality ('nix process creation is cheap) and use the shell to script things.

    The latter is far more flexible. I can write my own program and it's easy to plug into a shell script. Writing a plug-in module for a Windows app that is then scriptable within that app is much harder, if even possible at all (depends on the app).

    The difference between scripting MS Office and running a shell script is who is interpreting the script, and how easy is it to add functionality. Sure, strictly speaking the shell is an app too, but 'sh' is universally available on 'nix systems, so it's essentially part of the OS, which is not true of Office on Windows. (Now, if you could write equivalently powerful scripts in IE, you might have a point. You'd also be deeply vulnerable to every malicious URL out there. Oh, wait...)
  • by Animats ( 122034 ) on Tuesday October 21, 2003 @01:30AM (#7267732) Homepage
    Well, it does say "Until the TCP/IP implementation was released with Berkeley 4.2 in 1983, Unix had had only the weakest networking support." That's not true.

    Berkeley was Government-funded to develope it and give it away. That doesn't happen any more. Under the Bayh-Dole Act, universities can now own intellectual property rights in works developed with Government funding. The head of "intellectual property" at UC Berkeley said last year that if they'd had those rights back then, "they would have owned TCP/IP". But they wouldn't have; UCB would have been one player in a market.

    If UCB had owned those rights, the winning implementation might have been Phil Karn's K9AQ NOS [ka9q.net], because it was free software. It was free because Phil Karn, a radio ham, followed the traditions of the radio ham community, which just assumed everything was open.

    A related, but little-known fact: After 4.2BSD, DARPA decided to pull the plug on Berkeley's UNIX work. They felt that Berkeley's monolithic kernel was getting bloated, and decided to fund Mach (which was suppose to be a microkernel) instead. If the Mach effort had come out better, UNIX history could have been quit different.

Real Programmers don't eat quiche. They eat Twinkies and Szechwan food.

Working...