Two views of the Unix philosophy
[Posted October 14, 2003 by corbet]
We have recently received two books, both of which attempt to set down the
Unix philosophy. This philosophy is said to underlie the work we all do
with Linux, so discussions of it are worth a look. Maybe we can finally
find out what we have been trying to do all these years.
The first is The Art of Unix Programming by Eric Raymond (published
by Addison Wesley). We have
discussed this book before on these pages,
so a detailed look is not necessary at this time. Suffice to say that
Eric's book is now available in the stores. It is also available on the
net under a relatively restrictive Creative Commons license.
The other entry is Linux and the Unix Philosophy by Mike Gancarz,
published by Digital Press. This book appears to be a fairly
straightforward remake of Mr. Gancarz's The Unix Philosophy,
published in 1994. References to Linux have been retrofitted in, but the
book is little changed. If the underlying Unix philosophy is as enduring
as these books would have us believe, a book from 1994 should still be
current now. Unfortunately, Linux and the Unix Philosophy looks
old; consider, for example, the author's advice that a function's parameter
list should fit on a single line of an (80-column) screen. That might have
been good advice for an old-style C function, but, in the modern world,
where parameter names and types all go together, even a very short
parameter list can take multiple lines.
This book also ignores many of the features of modern Unix/Linux
programming, including scripting languages (beyond the shell) and graphical
interfaces. In Mr. Gancarz's view, all programs are small, and their
functions are minimal; he even states that multi-column output has bloated
the ls command excessively. Or consider:
Why has the metric of MIPS become such a hot issue in the computer
world today? Because as Unix usage has become more prevalent, the
use of small programs has proliferated as well. Small programs,
although they usurp little system memory when executing, derive the
most benefit from the injection of additional CPU horsepower.
This discussion does not fit your editor's world, where the best way to
improve the performance of a system is often to add memory.
The most interesting area of investigation, however, would be how the two
books characterize the Unix philosophy. Happily, both of them provide nice
sets of rules suitable for slides in any executive briefing - or a summary
table in LWN. So, without further ado...
| The Art of Unix Programming |
Linux and the Unix Philosophy |
|
Write a big program only when it is clear by demonstration that
nothing else will do.
|
Small is beautiful.
|
|
Design for simplicity; add complexity only where you must.
|
Make each program do one thing well.
|
|
Prototype before polishing. Get it working before you optimize
it.
|
Build a prototype as soon as possible.
|
|
(No rule, but portability is listed as one of the things Unix got
right).
|
Chose portability over efficiency.
|
|
Design programs to be connected with other programs.
|
Store data in flat text files.
Make every program a filter
|
|
Avoid hand-hacking; write programs to write programs when you can.
|
Use software leverage to your advantage. [i.e. reuse code].
|
|
Programmer time is expensive; conserve it in preference to machine
time.
|
Use shell scripts to increase leverage and portability.
|
|
In interface design, always do the least surprising thing.
|
Avoid captive user interfaces.
|
|
When a program has nothing to say, it should say nothing.
|
Silence is Golden
|
|
|
Look for the 90-percent solution.
Worse is better.
|
|
Design for visibility to make inspection and debugging easier.
|
|
|
Fold knowledge into data so program logic can be stupid and robust.
|
|
|
Repair what you can, but when you must fail, fail noisily and as
soon as possible.
|
|
|
Separate policy from mechanism; separate interfaces from engines.
|
|
|
Distrust all claims for the "one true way."
|
|
The further expression of these rules shows the relative age and limited
scope of Gancarz's book. He talks about flat text files, while Raymond
discusses the importance of transparent, textual network protocols as
well. Raymond covers the network, modern languages, and the ups and downs
of programming techniques as an integral part of his book; Gancarz has a
brief "Brave New World" chapter at the end where he treats bleeding-edge technologies
like the Internet, artificial intelligence, object-oriented programming,
and Java.
On the other side, Eric Raymond's tendencies are well known. The Art of
Unix Programming can be verbose and gives a lot of coverage to
Mr. Raymond's own work and beliefs. Most people would have found a way to
write a Unix book without including quotes from famous people on the evils
of gun control, for example.
Both books neglect areas of great concern for any contemporary software
developer. Neither will give as much help as the implementer of a web
browser, office suite, or DVD player might like. No developer can afford
to be
unaware of security issues in the current environment, but neither author
devotes any space to security. What is the Unix philosophy's
approach to security? Silence in response to that question is all too
telling.
In the end, if your editor had to choose between the two books, he would go
with The Art of Unix Programming, though both have their merits.
Readers of either would be well advised to heed Mr. Raymond's last rule,
however: distrust anybody who claims to know the "one true way."
(
Log in to post comments)