LWN.net Logo

The Art of Unix Programming

Eric Raymond first announced this project back in 1999: The Art of Unix Programming was to be a new book, written with help from the community, that would "attempt to explain the Zenlike 'special transmission, outside the scriptures' that distinguishes Unix gurus from ordinary mortals." More than three years later, a draft of the book is available for review.

The Art of Unix Programming is certainly not a beginner's programming manual. It assumes, instead, that the reader is already a competent hacker and is looking to learn more about the Unix way of doing things. So there is a lot of talk about philosophy and history, and a wealth of case studies. There is a lot of language like:

As with Zen art, the simplicity of good Unix code depends on exacting self-discipline and a high level of craft, neither of which are necessarily apparent on casual inspection. Transparency is hard work, but worth the effort for more than merely artistic reasons. Unlike Zen art, software requires debugging - and usually needs continuing maintenance, forward-porting, and adaptation throughout its lifetime. Transparency is therefore more than an esthetic triumph, but a victory that will be reflected in lower costs throughout the software's lifecycle.

Eric would, seemingly, like his book to be seen as a successor to the Kernighan and Plauger classics The Elements of Programming Style and Software Tools. This book shows some of the classic Raymond traits: no less than six case studies feature fetchmail (which he wrote), and the examples demonstrating the fortune file format are all about the evils of gun control. But there is some good stuff in there which has not necessarily been written down before. Eric is a good writer, and he has experience in the realm he is writing about. The Art of Unix Programming is worth a look.

We asked Eric a few questions about the draft release; here are his answers.

LWN: If you could characterize the art of programming in/for Unix as described in your book, in a single paragraph, how would you do it?

ESR: I'll do better, I'll boil it down to a single phrase. Keep it simple, stupid!

The true art of programming -- and this is something Unix guys were arguably the first to figure out and the most consistent at applying -- is minimizing global complexity. Most of the rest of the Unix philosophy pretty much falls out of that.

LWN: The draft as posted does not include any sort of licensing; will the final version be available under a free license?

ESR: Yes, but I haven't decided which one. There will be some restrictions on print reproduction, but none on electronic.

LWN: When you first announced the book project, it seemed you were planning to put the chapters out gradually and make use of a lot of community input. After chapter four, however (released almost exactly two years ago), things went quiet, and the rest of the book, seemingly, was done in a "cathedral" mode. Why is that? Did the more open approach not work out?

ESR: No, it's just that I stalled out for a long time and then gave it six weeks of intense work. This happened after an acquisitions editor at Addison-Wesley called me and said "Uh. Apparently you had an agreement to do a book with my predecessor, but I can't find a contract." There wasn't one; I have a twitch that way, I don't sign a contract until the book is essentially complete. He successfully nudged me into working on it again.

LWN: The book talks little about the programming of complex graphical applications, and avoids the GNOME/KDE issue altogether. Yet one could argue that complex applications are a big part of the future of Unix-like systems. There is often, however, a sort of impedance mismatch between fancy applications (think StarOffice 5) and the Unix way of doing things. What suggestions do you have for authors of graphical applications to help them carry forward the Unix tradition in the graphical world?

ESR: Separate policy from mechanism, because policy ages much faster than mechanism. Separate engines from interfaces, because tangling the two together tends to lead to unmaintainable messes. Don't give it a GUI if it doesn't need one.

Policy-mechanism separation is a major theme in the book. It's usually thought of in connection with X, but it can be applied a lot more widely -- and, in fact, Unix programmers *do* apply it a lot more widely without being really aware of the principle consciously.

(Yes, that's right, I'm doing another yet another book that's basically about conscious expression of unconscious folk practices. This would be #3. Is there anybody left who still finds this surprising? No? I thought not... :-))

One of the insights I got, one that's especially applicable to big gnarly GUI applications, is that Unix programmers divide all Gaul into three parts -- policy, mechanism, and glue. Mechanism is code that tells how to do things, policy is code that tells what to do -- and glue is the stuff that binds policy and mechanism together.

The punch line: glue is evil and must be destroyed, or at least minimized. Your typical huge honkin' C++ application with classes stacked twelve deep is an unmaintainable mess because the top two layers are policy, the bottom two are mechanism, and the middle eight are glue. And the trouble with glue is that it's opaque -- it impedes your ability to see clear down through the system from the top, or clear up from the bottom. You can't debug what you can't see through, because you can't form an adequate mental model of its behavior.

So my advice to GUI programmers is this: Decide what's policy and what's mechanism. Separate them cleanly -- ideally, have the GUI and engine running in separate processes, like gv and ghostscript or xcdroast and cdrecord. Then *ruthlessly eliminate all glue*. Or as much of it as you can, anyway.

LWN: There is very little treatment of security in the book. Why is that? Is, in your mind, security peripheral to the main art of Unix programming, or is something else going on?

ESR: It's peripheral. This is not a book about system administration, it's about how to design well. There's an aspect of that that has to do with secirity of course, but most of the things that make for good security (like minimizing code that has to be trusted) are just good engineering practice. That I *do* talk about a lot.

LWN: Unix has had a long run in the computing world, and, by all indications, it has a while to go yet. All good things come to an end eventually, however. What do you think might bring about the end of the Unix era, and what might replace Unix in the future?

ESR: My money is on capability-based persistent-object systems like EROS. But prophecy is difficult, especially about the future.


(Log in to post comments)

The Art of Unix Programming

Posted Feb 13, 2003 9:55 UTC (Thu) by leandro (subscriber, #1460) [Link]

I just checked the Eros OS site... the project seems dormant for almost two years, with only papers and a colateral source code control system to show in the last year. Any better references to its current state and progress, anyone?

quick review

Posted Feb 13, 2003 10:10 UTC (Thu) by coriordan (guest, #7544) [Link]

This book continues ESRs tradition of self-promotion and undermining the
Free Software Foundation (and RMS).

The subject matter is worthy of a book but I think it is very unkind to
rephrase history like this book does. Like the way ESR uses OpenSource
events/topics to spread his beliefs about gun ownership, this book about
programming and culture is used to create ESR's preferred history.

From reading this book, one would think that RMS was a hippy with silly
ideals, the FSF had little credibility in 1990, Linus finished the
operating system and the OpenSource (tm) movement brought "[GNU/]Linux" to
the next level.

Anyone who has read RMS's essays will know that he is a practical person.
Anyone who knows there history will know that the FSF had a well-respect
C compiler and the most robust debugger in the industry in 1990 (among
many other things).
Linus wrote an excellent *kernel*.
And... a bunch of companies with marketing plans got the term OpenSource
into mainstream usage.

Often, ESR will compliment the person/thing that is about to get a new
history, this may give the impression of fairness and many people will not
know the actual history anyway but to those who do know the history, the
truth (unbiased) would be a much bigger compliment.

Ciaran O'Riordan

quick review

Posted Feb 13, 2003 12:12 UTC (Thu) by mwilck (guest, #1966) [Link]

Yes. ESR's attempts to disqualify RMS and the FSF are pathetic, although other parts of the book seem to be well worth reading.

ESR fails to notice that many people have started seeing his "open source" movement as hype, whereas "free software" stands as a value no matter how many people believe in it. ESR writes:

For most hackers and almost all non-hackers, "Free software because it works better" easily trumped "Free software because all software should be free".

Problem: the first slogan could be proven wrong. Actually, there are strong indications that "the Kathedral and te Bazaar" told us how we wished the world to be rather than it actually was.

Now if people came to believe again that propietary software works better? By ESR's definition, all the pragmatists should leave the free sofware camp as quickly as they entered. Let's hope there'll be some idealists left to continue.

quick review

Posted Feb 13, 2003 17:49 UTC (Thu) by iabervon (subscriber, #722) [Link]

Now if people came to believe again that propietary software works better? By ESR's definition, all the pragmatists should leave the free sofware camp as quickly as they entered. Let's hope there'll be some idealists left to continue.

Like in the case of Bitkeeper? It is certainly the case that there are particular proprietary programs that work better than particular free programs, and the pragmatists do tend to use the proprietary ones. Of course, in many cases, the freedom of the code is a major pragmatic reason to prefer it: if you know that you will need to change things or that you will need to use the software beyond when it will be supported, no proprietary program could possibly work. The point of Free Software is to be useful to the users, with the idea that this requires the freedoms that the GPL gives the user. If the freedoms the GPL gives the user weren't actually useful, I'd except even RMS to abandon the ideal. If, for example, no two compilers were the same and no two programmers could understand each other's code, the GPL wouldn't be interesting.

The split isn't really between the pragmatists and the idealists, it's between the people who know from experience that free software is better and the people who only know from being told. The pragmatists and idealists would both abandon their positions if convinced that the software wasn't actually better; they differ only in how bad they think proprietary software is and how hard it would be to convince them. The non-technical end users have no use for the source themselves, and must therefore be convinced that there is a use to them to the source being available to those who what it; the open source message seems more effective than the free software message at this.

quick review

Posted Feb 14, 2003 13:08 UTC (Fri) by mwilck (guest, #1966) [Link]

It depends what you mean by "better". Of course, the GPL freedoms add values and usefulness to everyone (you can share the program legally with others, you can improve it to suit your needs, you can have independent parties scrutinize it).

It is not clear to me to which extent ESR is not talking about these added values when he says "free software is better". I suspect a to very little extent - he means "technically better", nothing but, in the sense in which Bitkeeper is better than CVS and Microsoft Word better than Kword. This is what many non-technical users will probably also do, especially because it hardly matters to them if copying stuff is legal or not.

I think it is possible to convey the benefits of free software to non-technical users, too. A democratic constitution gives its citizens a lot of rights many of them never exert - nevertheless it seems to be clear that people still appreciate that they have these rights.

Just repeating the message "free software is technically better" without talking about the additional freedoms is dangerous. You may convince more people in the short run, but you risk to loose them when they come to believe that proprietary software is technically superior.

quick review

Posted Feb 16, 2003 0:25 UTC (Sun) by socket (guest, #43) [Link]

You make some good points. I've often found myself describing the difference between Raymond and Stallman in terms of pragmatism vs. ideology, knowing that it oversimplifies. I like your explanation of the more subtle points.

To address a part of your comment:

The non-technical end users have no use for the source themselves, and must therefore be convinced that there is a use to them to the source being available to those who what it; the open source message seems more effective than the free software message at this.

I disagree that end users have no use for source. My girlfriend's started using Linux recently, and doesn't do programming (yet. Perhaps she might, at some point, but it doesn't much matter.) When things go wrong on her Windows partition, there's not much I can do - I'm thoroughly unfamiliar with Windows anymore, and often all you can really do is uninstall and reinstall and hope the bug goes away. When something goes wrong on her Linux system, it's much easier to track down and fix. I haven't had to dig into source code yet to fix anything on her system (though I have on my own) but I'm much happier simply having that option. And she's much happier knowing that it can probably be fixed.

I'm certainly not the best programmer, though. But if I can't fix it, I can find someone more competent who can. A large benefit of running free software is that developers are more open to listening to their users, when it's a polite, informed question or bug report. Until more companies read The Cluetrain Manifesto and take it to heart, commercial software will be at a disadvantage because of the iron gate between developers and users. Even if nobody I know can fix it, given the source code, the relationship between users and developers is more often such that bug reports often do some good, and are likely to get fixed faster than in commercial software - I find that free software developers typically have an attachment to their project and their code that you don't find in commercial software; it's something they made because they need it, and care about it, and it's rare to have the same kind of interest in an employer's project than one you work on of your own incentive.

I think pragmatism and idealism are both necessary elements to the quality and success of free software. The fact is, people care about it.

I tend to refer to "free software" more often than "open source," but I generally mean the same thing by it. I think it's good that both Eric Raymond and Richard Stallman exist, because different people will gravitate toward different ideologies. The companies may have come to free software via Eric Raymond's publicization, and many would like to not fully embrace Stallman's strong stance on what that should mean, but on the whole, I'm happier that these companies are more free than they used to be. I may philosophically feel closer to Stallman, but I'd rather have partially free than non-free.

quick review

Posted Feb 16, 2003 8:36 UTC (Sun) by Odinson (guest, #1402) [Link]

In the spirit of KISS...

The source is important because _SOMEBODY_ can fix it. I fix my own car/bike beacuse I know how.

Most geeks go to a mechanic.

quick review

Posted Feb 20, 2003 19:37 UTC (Thu) by mmarq (guest, #2332) [Link]

THIS PRAGMATISM VS IDEALISM IS JUST CRAP!!

They are the same! Idealism without pragmatism would be like in a perpetual dream, and pragmatism without idealism could not happen, because it would not have a conceptual blueprint, a point of start...I think that in a common sense (not philosofical) people tend to be just like that, "balanced". But is also true that the "idealism" or concept of "pure" materialism tend to view itself as without any form of idealism, silly ins't it?...

SO, JUST LET US TRY TO CUT THE CRAP, IT ONLY REFLECTS THE ANGER IN US, AND IT WONT SOLVE ANY PROBLEMS...

The Art of Unix Programming

Posted Feb 13, 2003 13:31 UTC (Thu) by anr (subscriber, #234) [Link]

Quoting the article:

[N]o less than six case studies feature fetchmail (which he wrote), and the examples demonstrating the fortune file format are all about the evils of gun control.

Some questions:

  • fetchmail has had a very bad security history (full of buffer overflows). Is it a good example of UNIX programming?
  • what's pro-gun propaganda doing in a book about programming? Spare us the ideology, please. (disclaimer: I am an anti-gun person).

The Art of Unix Programming

Posted Feb 13, 2003 15:10 UTC (Thu) by erat (guest, #21) [Link]

1) Lots of software that's well written has a security goof every now and then. Sometimes it isn't the software itself, but a library that it's linked against that's causing the problem. The Linux kernel gets security issues too, but I don't see anyone questioning whether or not it's a quality piece of sofware (it's gotten a bit too "kitchen sink"-ish for my taste, but it's still a high quality piece of work).

2) I have no problem with guns, but even I don't like pro-gun propaganda in the books I read (unless I'm reading a pro-gun book, of course, which is something I've never done).

At the risk of causing ESR to gripe again about how "...[his] own people turn[ed] on [him]...", I'll state that (IMHO) the best thing ESR can do is divorce his writing from his ego and politics and let his technical prowess be the main focus. He's a great guy (I met him once at a local LUG meeting), he's technically brilliant, and he's a fantastic writer, but his ego is the size of Mt. Everest and quite often it seems to get in the way. Case in point: we're discussing his political views on the FSF and gun control instead of the technical merits of the book. How many times does this need to happen before he realizes he'd be doing the community a much more valuable service by just sharing his technical wisdom?

The Art of Unix Programming

Posted Feb 13, 2003 19:27 UTC (Thu) by giraffedata (subscriber, #1954) [Link]

Come on, guys. The book doesn't contain a chapter promoting gun freedom; it just uses pro-gun statements in example text. The example text had to exist one way or another; can't readers just ignore the content?

From a practical point of view, though, I can agree with the point that ESR would be better off using neutral example text. A writer has to take a reader as he finds him, and if the reader is delicate, the writer has to treat him delicately or risk losing the reader.

--
Bryan Henderson
San Jose, California

The Art of Unix Programming

Posted Feb 13, 2003 19:29 UTC (Thu) by JoeBuck (subscriber, #2330) [Link]

The kernel is a vastly bigger program than fetchmail, and it is a highly parallel program, while fetchmail is a sequential program. The kernel must protect one process from interfering with another and enforce privilege; for fetchmail the issues are far simpler. Given this, one would expect to see vastly more security issues in the kernel. For its size, fetchmail has had an unexpectedly large number of security holes. It's not unreasonable to ask why this is so.

The Art of Unix Programming

Posted Feb 23, 2003 6:42 UTC (Sun) by linuxtech (guest, #459) [Link]

At the risk of causing ESR to gripe again about how "...[his] own people turn[ed] on [him]..."...

I missed that, care to explain or show us where it is posted?

The Art of Unix Programming

Posted Feb 13, 2003 20:28 UTC (Thu) by edgewood (subscriber, #1123) [Link]

If you don't like Eric's choice of example text, you're free not to buy the book, or write your own.

The Art of Unix Programming

Posted Feb 14, 2003 13:20 UTC (Fri) by mwilck (guest, #1966) [Link]

Sure I can. That's not the point. His egomania draws the attention away from the good parts of the text. Probably it's not even the fact that some people don't share ESR's opinion on gun control. It's the fact that he is bringing up the issue _repeatedly_ in a technical context. He just can't help himself, and that disqualifies him - at least partly - as a technical writer.

The Art of Unix Programming

Posted Feb 13, 2003 22:22 UTC (Thu) by jschrod (subscriber, #1646) [Link]

You've read the answer: Security belongs in the realm of sysadmins, is not important enough for a book about programming.

This opinion alone disqualifies the book, IMNSHO. Only when programmers grasp that it is inherently their task to produce secure software, we will come out of this mess we're in currently. Just have a look at the latest SQL-slammer worm problem - that was not a sysadmin problem, it is a programming problem. (In relation, few systems were taken over and the worm was not dangerous, but the consequences were already large.) And this issue comes up again and again and again.

(mechanism,policy,glue) parallel to (model,view,controller)

Posted Feb 13, 2003 21:15 UTC (Thu) by dneto (guest, #4954) [Link]

The best designs in the GUI world tend to boil down to
a three-way partitioning of the design. As I know it,
this was "discovered" by the early SmallTalk community
and named the Model-View-Controller paradigm.

This is very closely matched by the separation of
mechanism, policy and glue.
"Mechanism" is roughly equivalent to the data "model",
"policy" is roughly equivalent to your UI view,
and "glue" is much like the controller code that
hooks them up.

So the GUI community already knows the basic tenets,
and enunciated it long ago. But it's always worth
repeating.

As an example, the Glade tool naturally cleaves
your UI policies from your underlying model.

Fetchmail as an example??

Posted Feb 15, 2003 1:12 UTC (Sat) by bronson (subscriber, #4806) [Link]

It's somewhat strange that ESR would use Fetchmail as an example of good design. In my experience with Fetchmail has been rather poor. The configuration file is a complete disaster, the program bloated, and the code is fairly convoluted (or was -- it's been a while). This is all the worse since the problem it solves is fundamentally rather simple.

I wrote and maintained Trestlemail (a Fetchmail "plug-out") for a few years. Easily 2/3 of the people contacting me for help were actually having Fetchmail issues and, thanks to the overly complex configuration and painful error messages, didn't know it.

Look to GetMail for Fetchmail done right. (It's even written in ESR's vaunted Python).

Despite this, it looks like ESR's book has some valuable insights.

The Art of Unix Programming

Posted Feb 15, 2003 4:19 UTC (Sat) by tjc (guest, #137) [Link]

Like Unix, OS/2 was built to be multitasking and would not run on a machine without an MMU (early versions simulated an MMU using the 286's memory segmentation).

Is this right? IIRC Xenix ran on a 286, so it must have had an MMU.

Re: MMU

Posted Feb 17, 2003 20:19 UTC (Mon) by Ross (subscriber, #4065) [Link]

It could do segmenting, but not paging.

The Art of Unix Programming

Posted Feb 20, 2003 18:57 UTC (Thu) by mmarq (guest, #2332) [Link]

Since the dead of "punch cards" programing that software has emerged as a independent craft or discipline whit its very own merits and "quirks"...and it as been very much so because it relied for many years on the same concept of computacional machine, whit "CPU, MEMORY, and "SIMPLE I/O"!....BUT THE MACHINE IS EVOLVING NOW, AND VERY FAST. It's not only NUMA or CLUSTER typical machines but even the typical PC or WORKSTATION("the 90% of them"TM) that are accelerating like hell!!!...i would like to point you to the excelent analises fount at http://www.inqst.com/articles/io/0111main.htm ,....
The computacional machine "is diverging", due IMO to the pressures of the "information society" that introduced so many digital media formats. So the machine is diverging, by pressure of markets and efficiency, into some king of "nodes" to address the special requirements of I/O and peripherals, be it "protocols", "buses" or others.

So IMHO, as far as kernel programming is concerned, "GLUE" IS THE MOST IMPORTANT PART OF IT"... better!!!, even a excelent and very well crafted kernel, like the Linux kernel would not live very long without the "GLUE" to address the needs of the various media formats and them perifheral interfaces.

As for "userspace" programming concern, i think the book as far i read it is a good work and a "must have", from a good and experienced programmer.

Can anyone explain me "why do i feel this concious denial of any relationchip of dependence whit media and hardware" from "Unix hackers and gurus", that then perhaps reflects in "inconcious practices"???...
Is it just me, or "Unix hackers and gurus" think that software can submit and determine hardware and media formats???...MS "almost" does it by market, not code...

Any light would be very well come.

_________//__________

Mario Marques
system integrator and seller
mmarq@netvisao.pt

Eric's technical prowess

Posted Feb 22, 2003 7:49 UTC (Sat) by cypherpunks (guest, #1288) [Link]

Eric is an incompetent programmer. I know plenty of people at MIT who've worked with him. They said he couldn't code. He's spent the past many years with no real job, beyond working on free software. In that time, he's managed to get laughed off of the Linux Kernel Mailing list, failed to implement a large number of projects, and his sole causes for fame are rewriting Fetchmail (which is simple enough that I could have written it as a term project as an undergrad), and being the first to implement one particular (rather trivial) algorithm for spam filtering.

His Cathedral and Bazaar, rather than describing what happens, is a very eloquent description of what some people would like to happen in some ideal world that doesn't exist.

Isn't it a bit ironic that he, of all people, is writing a book on programming? Wouldn't we be better off reading it from someone who knows how to program, rather than just how to write convincingly?

Why does LWN bother to give him coverage, and to interview him? Given the high quality of past coverage, and the high level of bullshit filters built into LWN's editors, seeing the article suprised me.

The Art of Unix Programming

Posted Feb 25, 2003 9:03 UTC (Tue) by cypherpunks (guest, #1288) [Link]

Wow, the trolls are out in force today. (And posting as cypherpunks, it
would seem. :)

So you're jealous that when Eric writes a book it's considered news, but
when you write a book... Well, you don't, do you? That would be too
much like work.

The "gun control" example is obviously from the same file that puts
random .sigs on the end of his messages. This would be a "real world
example of what he has on his machine." You'll notice all his examples
are real world examples of actual code in the field (modulo one or two
where passwords were removed). He used (yeah, over-used) fetchmail
because it's a project with which he is intimately familiar. (I don't
use it myself.)

And you can always email HIM about it. He did ASK for comments about the
book, put a public rough draft out on the net. And how many had
constructive comments? (Afraid to face him in email? Aww, isn't that
cute...)

"Hot grits. Natalie portman. It should be called 'The art of GNU/Unix
Programming'. ESR stole RMS's thunder, and RMS wants it back, dammit!"

Don't mind me, I just find it all terribly amusing...

A random, anonymous poster. :)

The Art of Unix Programming

Posted Oct 18, 2003 0:21 UTC (Sat) by chip (subscriber, #8258) [Link]

<applause>

Copyright © 2003, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds