Preface
前言
Unix is not so much an operating system as an oral history.
--Neal Stephenson
與其說Unix是個操作系統,不如說是一部口述史。
——Neal Stephenson
There
is a vast difference between knowledge and expertise. Knowledge lets
you deduce the right thing to do; expertise makes the right thing a
reflex, hardly requiring conscious thought at all. This book has a lot
of knowledge in it, but it is mainly about expertise. It is going to
try to teach you the things about Unix development that Unix experts
know, but aren’t aware that they know. It is therefore less about
technicalia and more about shared culture than most Unix books — both
explicit and implicit culture, both conscious and unconscious
traditions. It is not a ‘how-to’ book, it is a ‘why-to’ book.
“知”(書本知識)與“識”(專業的技術經驗)有著天壤之別。“知”使你以推理演繹出正確之事物;“識”則使你幾乎無須下意識的去思考,就得出正確結論,好象條件反射一樣。雖然本書中寫滿了“知”,但這些卻都關乎于“識”。它將試圖傳授你有關Unix開發之事物,這些雖為Unix專家所知曉,但他們卻未意識到自己知道。故此,較之大多數Unix書籍,本書寡談于技術,而偏多于共享文化——包涵其外在與內在之文化,以及有意與無意造成之習俗。所以說,這不是本關于“如何”的書,而是本關于“為何”的書。
The
why-to has great practical importance, because far too much software is
poorly designed. Much of it suffers from bloat, is exceedingly hard to
maintain, and is too difficult to port to new platforms or extend in
ways the original programmers didn’t anticipate. These problems are
symptoms of bad design. We hope that readers of this book will learn
something of what Unix has to teach about good design.
因為太多軟件設計之拙劣,故“為何”有著巨大實用價值。那些大多遭受注水般填塞折磨的軟件,極難以維護,倘若欲移植到新平臺,或以原作者未曾預計之方向擴展,皆非常之難。這些問題均為不良設計之病象。我們希望本書讀者能學到Unix以其所具有之良好設計所傳授給你的東西。
This
book is divided into four parts: Context, Design, Tools, and Community.
The first part (Context) is philosophy and history, to help provide
foundation and motivation for what follows. The second part (Design)
unfolds the principles of the Unix philosophy into more specific advice
about design and implementation. The third part (Tools) focuses on the
software Unix provides for helping you solve problems. The fourth part
(Community) is about the human-to-human transactions and agreements
that make the Unix culture so effective at what it does.
本書分為四部分:背景、設計、工具和社團。第一部分(背景)是哲學和歷史,為隨后部分提供基礎和動機。第二部分(設計)深入剖析Unix哲學原理,一直到得出與設計和實現有關的明確指點。第三部分(工具)著眼于Unix提供給你以助于解決問題的軟件。第四部分(社團)介紹人際間的交流和約定,正如它們做出的那樣,這些使Unix文化產生了非常深遠的影響。
Because
this is a book about shared culture, I never planned to write it alone.
You will notice that the text includes guest appearances by prominent
Unix developers, the shapers of the Unix tradition. The book went
through an extended public review process during which I invited these
luminaries to comment on and argue with the text. Rather than
submerging the results of that review process in the final version,
these guests were encouraged to speak with their own voices, amplifying
and developing and even disagreeing with the main line of the text.
因為這是一本關于共享文化的書,所以我從未想過獨自去完成它。你應該會發現書中包括一些由杰出的Unix開發者和Unix習俗締造者所寫的客串文章。在我邀請這些博學的人來評論和爭辯書中文字時,本書也經歷了一次廣泛的公眾審閱過程。與其在成書時,將這評論的過程掩去,不如讓這些佳賓說出自己的聲音,雖然于本書主旨,可能使其充實,可能使其延伸,甚至也可能與其偏離。
In
this book, when I use the editorial ‘we’ it is not to pretend
omniscience but to reflect the fact that it attempts to articulate the
expertise of an entire community.
在本書中,當我用“我們”的口吻時,不是我想裝成全知全能的上帝,而是想表達一個事實,它正努力成為整個社團的“識”。
Because
this book is aimed at transmitting culture, it includes much more in
the way of history and folklore and asides than is normal for a
technical book. Enjoy; these things, too, are part of your education as
a Unix programmer. No single one of the historical details is vital,
but the gestalt of them all is important. We think it makes a more
interesting story this way. More importantly, understanding where Unix
came from and how it got the way it is will help you develop an
intuitive feel for the Unix style.
因為本書的宗旨是傳播文化,所以較之那些正經的技術書籍,講了更多的歷史傳說以及題外話。好好享受吧,這些也是培養你成為Unix程序員的一部分。整個偉大的歷史是由那些細枝末節的事情組成的。我們認為這種方式會使故事更有趣。更重要的是,明白了Unix從哪里來以及如何踏上這條路,會助你培養Unix方式的直覺。
For
the same reason, we refuse to write as if history is over. You will
find an unusually large number of references to the time of writing in
this book. We do not wish to pretend that current practice reflects
some sort of timeless and perfectly logical outcome of preordained
destiny. References to time of writing are meant as an alert to the
reader two or three or five years hence that the associated statements
of fact may have become dated and should be double-checked.
出
于同樣的原因,我們也不愿把歷史寫成好像已經結束了似的。你會發現在這本書中有非常多的地方指出了寫作的時間。我們不希望把當前的慣例說成永恒真理之一,
并且是命中注定。指明寫作的時間意味著,對讀者來說,這是一個警告。兩年、三年抑或五年之后,這個情況的相關陳述可能已經過時,而且你要加倍小心。
Other
things this book is not is neither a C tutorial, nor a guide to the
Unix commands and API. It is not a reference for sed or Yacc or Perl or
Python. It’s not a network programming primer, nor an exhaustive guide
to the mysteries of X. It’s not a tour of Unix’s internals and
architecture, either. Other books cover these specifics better, and
this book points you at them as appropriate.
另外,這本書既不是一本C語言教程,也不是Unix 命令和API 的指南。它不是一本sed或者Yacc或者Perl或者Python的參考,也不是一本網絡編程入門,更不是一本關于神秘的X的詳盡指南,當然也不是一個Unix內核和架構的導讀。其它書籍更好的覆蓋了這些細節,本書會在適當的時候把它們指給你。
Beyond
all these technical specifics, the Unix culture has an unwritten
engineering tradition that has developed over literally millions of
man-years of skilled effort. This book is written in the belief that
understanding that tradition, and adding its design patterns to your
toolkit, will help you become a better programmer and designer.
在所有這些技術細節之外,Unix文化有著一個傳統,毫不夸張的講,這個傳統已經以嫻熟之努力發展了數百萬人年。力求讓你理解這個傳統,并把它那種設計模式添入你的工具箱中,以助你成為一個優秀的程序員和設計師,是本書寫作的信念。
Cultures
consist of people, and the traditional way to learn Unix culture is
from other people and through the folklore, by osmosis. This book is
not a substitute for person-to-person acculturation, but it can help
accelerate the process by allowing you to tap the experience of others.
民眾造就文化,習慣上,我們從傳說中和他人那里學習Unix文化,這種學習是潛移默化的。本書不是一個人際文化交流的替代品,但它允許你分享他人的經驗,以助于加快這個過程。
Who Should Read This Book
本書適合誰
You
should read this book if you are an experienced Unix programmer who is
often in the position of either educating novice programmers or
debating partisans of other operating systems, and you find it hard to
articulate the benefits of the Unix approach.
如果你是一個富有經驗的Unix程序員,經常出現在那些指點新手程序員的地方,或者你時常和其他派系的操作系統支持者爭辯,卻苦于無法把和Unix類似系統的優點講清楚,那么,你應該讀這本書。
You
should read this book if you are a C, C++, or Java programmer with
experience on other operating systems and you are about to start a
Unix-based project.
如果你曾經是一個在其他操作系統上有經驗的C,C++或者Java程序員,而你又準備開始一個基于Unix的工程時,你應該讀這本書。
You
should read this book if you are a Unix user with novice-level up to
middle-level skills in the operating system, but little development
experience, and want to learn how to design software effectively under
Unix.
如果你是一個從新手向中級水平邁進的Unix操作系統使用者,但有一點點開發經驗,又想學習如何在Unix下有效的設計軟件,那么你應該讀這本書。
You
should read this book if you are a non-Unix programmer who has figured
out that the Unix tradition might have something to teach you. We
believe you’re right, and that the Unix philosophy can be exported to
other operating systems. So we will pay more attention to non-Unix
environments (especially Microsoft operating systems) than is usual in
a Unix book; and when tools and case studies are portable, we say so.
如果你是一個領悟到可能從Unix傳統中受益的非Unix程序員,你應該讀這本書。我們相信你是對的,因為Unix哲學可以應用到其它操作系統中去。故此不象一本普通的Unix書籍,我們對非Unix環境(尤其是微軟的操作系統)投以更多的關注。并且當工具和實例研究是可移植時,我們也會指出。
You
should read this book if you are an application architect considering
platforms or implementation strategies for a major general-market or
vertical application. It will help you understand the strengths of Unix
as a development platform, and of the Unix tradition of open source as
a development method.
如果你是一個應用程序架構師,正在考慮各種平臺,或者為主要的通用市場,不然就是縱向應用選擇不同的實現策略時,你應該讀這本書,它會助你了解Unix作為一個開發平臺的實力,以及把開源作為開發方法的Unix傳統。
You
should not read this book if what you are looking for is the details of
C coding or how to use the Unix kernel API. There are many good books
on these topics; Advanced Programming in the Unix Environment
[Stevens92] is classic among explorations of the Unix API, and The
Practice of Programming [Kernighan-Pike99] is recommended reading for
all C programmers (indeed for all programmers in any language).
如果你正在找一本,關于C編碼細節或者如何使用Unix內核API的書,那么你不應該讀這本書。在這些方面有太多的好書,《Unix環境下高級編程》[Stevens92]是一本在Unix API之間歷險的經典書籍,《程序設計實踐》[Kernighan-Pike99]也被所有C程序員作為推薦讀物(實際上,天下間程序員都應該看)。
How to Use This Book
如何使用本書
This
book is both practical and philosophical. Some parts are aphoristic and
general, others will examine specific case studies in Unix development.
We will precede or follow general principles and aphorisms with
examples that illustrate them: examples drawn not from toy
demonstration programs but rather from real working code that is in use
every day.
這本書既關心實踐也關心哲學。它的一部分是格言和普適原理,其它部分則是分析在研究Unix發展中的特殊情況。通常在格言和普適原理之前或之后,我們將為它們舉出實例。這些實例不是從玩具程序中抽取出來的,而是從一些如今每天都在用的,可以真正運行的代碼中抽取的。
We
have deliberately avoided filling the book with lots of code or
specification-file examples, even though in many places this might have
made it easier to write (and in some places perhaps easier to read!).
Most books about programming give too many low-level details and
examples, but fail at giving the reader a high-level feel for what is
really going on. In this book, we prefer to err in the opposite
direction.
我
們盡量避免用大量的,像代碼或規范文件這樣的例子來填塞本書,雖然在很多地方這會使寫起來容易些(或許在某些地方更容易讀!)。許多與編程有關的書籍給出
了大量低水平的細節和例子,而想這樣讓讀者對實際的后續部分有一個高層次的認識,無疑是失敗的。我們反其道行之,哪怕步入歧途。
Therefore,
while you will often be invited to read code and specification files,
relatively few are actually included in the book. Instead, we point you
at examples on the Web.
所以,當你需要經常性的閱讀代碼和規范文件時,相關部分通常很少會包含在書中。相反,我們會在Web上給出例子
Absorbing
these examples will help solidify the principles you learn into
semi-instinctive working knowledge. Ideally, you should read this book
near the console of a running Unix system, with a Web browser handy.
Any Unix will do, but the software case studies are more likely to be
preinstalled and immediately available for inspection on a Linux
system. The pointers in the book are invitations to browse and
experiment. Introduction of these pointers is paced so that wandering
off to explore for a while won’t break up exposition that has to be
continuous.
理解這些例子會幫助你鞏固你所學到的原理,并把它們變成你工作時的一種近乎于本能的知識。比較理想的是,在你讀這本書時,你旁邊有一個運行Unix的終端,以及一個唾手可得的Web瀏覽器。任何的Unix都可以,但是在一個Linux系統中,你應該檢查我們用于實例研究的軟件是否已經預先安裝好,并且馬上可以用。當需要你上網查閱或者做實驗時,我們會給你指出。這些把你像神游一樣的指向它處的說明是順暢的,絲毫不會打斷你原本進行的閱讀。
Note:
while we have made every effort to cite URLs that should remain stable
and usable, there is no way we can guarantee this. If you find that a
cited link has gone stale, use common sense and do a phrase search with
your favorite Web search engine. Where possible we suggest ways to do
this near the URLs we cite.
注意:雖然我們盡力去引用穩定和可用的URL,但我們無法保證這一點。如果你發現一個我們引用的鏈接失效了,那么,像平時一樣,在你喜歡的Web搜索引擎上做一個短語搜索。以這種辦法得到的結果應該和我們引用的URL差不多。
Most
abbreviations used in this book are expanded at first use. For
convenience, we have also provided a glossary in an appendix.
本書中的大多縮略詞在首次使用時是以完整形式出現的。為了方便起見,我們在附錄也提供了一個術語表。
References
are usually by author name. Numbered footnotes are for URLs that would
intrude on the text or that we suspect might be perishable; also for
asides, war stories, and jokes.
參考資料通常以作者姓名排序。那幾個有限的腳注都是些本應加入正文或者容易失效的URL,以及一些題外話,戰爭故事,還有笑話。
To
make this book more accessible to less technical readers, we invited
some non-programmers to read it and identify terms that seemed both
obscure and necessary to the flow of exposition. We also use footnotes
for definitions of elementary terms that an experienced programmer is
unlikely to need.
為了使幾乎不懂技術的讀者能理解這本書,我們邀請了一些不是程序員的人來讀這本書,以便找出那些在敘述過程中必需的,但是有些晦澀的術語。我們也把一些基本術語的解釋放入了腳注,雖然對有經驗程序員可能不需要。
Related References
相關參考資料
Some
famous papers and a few books by Unix’s early developers have mined
this territory before. Kernighan & Pike’s The Unix Programming
Environment [Kernighan-Pike84] stands out among these and is rightly
considered a classic. But today it shows its age a bit; it doesn’t
cover the Internet, and the World Wide Web or the new wave of
interpreted languages like Perl, Tcl, and Python.
以前,在涉足這個領域的少數Unix早期開發者所著的書和著名論文中,Kernighan和Pike的《Unix編程環境》[Kernighan-Pike84]脫穎而出,成為了一本經典著作。但是今天它看起來有點陳舊了,它沒有包含Internet和World Wide Web,也沒有預見到如今的解釋語言浪潮,好象Perl,Tcl和Python。
About
halfway into the composition of this book, we learned of Mike Gancarz’s
The Unix Philosophy [Gancarz]. This book is excellent within its range,
but did not attempt to cover the full spectrum of topics we felt needed
to be addressed. Nevertheless we are grateful to the author for the
reminder that the very simplest Unix design patterns have been the most
persistent and successful ones.
在這本書的寫作其間,我們拜讀了Mike Gancarz的《Unix哲學》[Gancarz]。它是這個領域里一本極好的書。但是它沒有涵蓋這個主題的所有延伸范圍,而這卻是我們認為也應該去寫的。不過,我們仍然要感謝作者,關于那些已經非常穩定和成熟,可又十分樸素的Unix設計模式,作者給了我們很多提示。
The
Pragmatic Programmer [Hunt-Thomas] is a witty and wise disquisition on
good design practice pitched at a slightly different level of the
software-design craft (more about coding, less about higherlevel
partitioning of problems) than this book. The authors’ philosophy is an
outgrowth of Unix experience, and it is an excellent complement to this
book.
《注重實效的程序員》(又譯《程序員修煉之道》)[Hunt-Thomas]是一本詼諧和睿智的專題集,談論良好的注重實效的設計,著眼于軟件設計工藝(更多關注編碼,而不是較高層次上的問題劃分)的不同層次。作者的哲學來自于Unix上的經驗,是本書的一個極好的補充。
The
Practice of Programming [Kernighan-Pike99] covers some of the same
ground as The Pragmatic Programmer from a position deep within the Unix
tradition.
《程序設計實踐》[Kernighan-Pike99]關注的范圍和《注重實效的程序員》相同,但在Unix傳統方面更深入。
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.
最后(毫無疑問那會招來憤怒),我們推薦《Zen Flesh, Zen Bones》[Reps-Senzaki],
這是一個佛教禪宗入門資料的重要收錄集,對禪宗的引證遍及這本書的各處。之所以在這里包括這本書,是因為在為那些對軟件設計產生了非常重要的,但同時又難
以領悟的思想取名時,禪宗給我們提供了一個詞匯表。有宗教信仰的讀者可以把禪宗作為一個改善智力的訓練方式,而不是把它作為一種宗教來看——從純粹的無神
論角度來看,禪宗也的確是這樣的。
Conventions Used in This Book
本書中的約定
The
term “UNIX” is technically and legally a trademark of The Open Group,
and should formally be used only for operating systems which are
certified to have passed The Open Group’s elaborate
standards-conformance tests. In this book we use “Unix” in the looser
sense widely current among programmers, to refer to any operating
system (whether formally Unix-branded or not) that is either
genetically descended from Bell Labs’s ancestral Unix code or written
in close imitation of its descendants. In particular, Linux (from which
we draw most of our examples) is a Unix under
this definition.
從技術以及法律上來說,術語“UNIX”是屬于Open Group的商標,而且它要能夠通過Open Group的符合標準的精心測試,這樣的操作系統才能正式使用這個名稱。在這本書中,我們所談及的“UNIX”范圍比較寬泛,我們指的是通常程序員們指的那些操作系統(不管有沒有被正式地打上“UNIX”標志),它可能衍生于貝爾實驗室的那個UNIX始祖的源代碼,也可能是那些被寫的象UNIX后代的仿造品。特別地,在這個定義下,Linux(大多數我們引用的例子都來自于它)也是一個Unix。
This
book employs the Unix manual page convention of tagging Unix facilities
with a following manual section in parentheses, usually on first
introduction when we want to emphasize that this is a Unix command.
Thus, for example, read “munger(1)” as “the ‘munger’ program, which
will be documented in section 1 (user tools) of the Unix manual pages,
if it’s present on your system.” Section 2 is C system calls, section 3
is C library calls, section 5 is file formats and protocols, section 8
is system administration tools. Other sections vary among Unixes but
are not cited in this book. For more, type man 1 man at your Unix shell
prompt (older System V Unixes may require man –s 1 man).
在標記Unix工具時,這本書采用了Unix手冊頁的習俗。在我們想強調的Unix命令首次出現時,我們在其后的圓括號里加上了手冊頁的章節。例如,當看到“munger(1)”時,那就表示“程序munger,如果你的系統提供的話,它的文檔在Unix手冊頁的第一部分(用戶工具)里”。第二部分是C系統調用,第三部分是C函數庫調用,第五部分是文件格式和協議,第八部分是系統管理員工具。對于各種Unix手冊頁的其他部分,本書沒有提及。要想獲得更多了解的話,就在你的Unix shell提示符下鍵入man 1 man(對于古老的System V Unix,可能需要輸入man –s 1 man)。
Sometimes
we mention a Unix application (such as Emacs, without a manual-section
suffix and capitalized. This is a clue that the name actually
represents a well-established family of Unix programs with essentially
the same function, and we are discussing generic properties of all of
them. Emacs, for example, includes xemacs.
有些時候,我們提到一個Unix應用程序(例如Emacs)時卻沒有帶手冊頁章節后綴,并且首字母是大寫。這表明這個名字在這里,實際上描述一個本質上有著相同功能的,已經被確定好的Unix程序家族。這時我們只討論它們的共有的性質。例如,Emacs包括xemacs。
At
various points later in this book we refer to ‘old school’ and ‘new
school’ methods. As with rap music, new-school starts about 1990. In
this context, it’s associated with the rise of scripting languages,
GUIs, open-source Unixes, and the Web. Old-school refers to the
pre-1990 (and especially pre-1985) world of expensive (shared)
computers, proprietary Unixes, scripting in shell, and C everywhere.
This difference is worth pointing out because cheaper and less memory
constrained machines have wrought some significant changes on the Unix
programming style.
在本書隨后的不同地方,我們會提到“舊學派”和“新學派”方法。大約在1990年,伴隨著rap音樂,新學派出現了,它的出現和當時腳本語言,GUI,開源Unix以及Web的興起有關。舊學派指的1990年以前(尤其是1985年以前)的學術界,那些人用著昂貴(共享)的計算機,私有的Unix,shell下的腳本以及無處不在的C。這個差異絕對值得指出,因為廉價以及幾乎沒有內存限制的機器使得Unix編程風格發生了重大的改變。
Our Case Studies
我們的實例研究
A
lot of books on programming rely on toy examples constructed
specifically to prove a point. This one won’t. Our case studies will be
real, pre-existing pieces of software that are in production use every
day. Here are some of the major ones:
大多數關于編程的書都依靠一些特別創建的玩具例子來證明一個觀點,本書卻不想這樣。我們學習的例子是真實的,是我們每天都在使用的成品軟件的一部分。下面是主要的幾個:
cdrtools/xcdroast These
two separate projects are usually used together. The cdrtools package
is a set of CLI tools for writing CD-ROMs; Web search for “cdrtools”.
The xcdroast application is a GUI front end for cdrtools; see the
xcdroast project site [http://www.xcdroast.org/].
Cdrtools/xcdroast 這兩個單獨的項目通常被放在一起。Cdrtools包是一套刻錄CD-ROM的CLI工具集。可以在Web上搜索一下“cdtools”。xcdroast是為cdrtools寫的一個GUI前端應用程序。參見xcdroast項目站點[http://www.xcdroast.org/]。
fetchmail The
fetchmail program retrieves mail from remote-mail servers using the
POP3 or IMAP post-office protocols. See the fetchmail home page
[http://www.catb.org/~esr/fetchmail] (or search for “fetchmail” on the
Web).
fetchmail fetchmail是一個使用POP3或者IMAP郵件傳輸協議,從遠程郵件服務器上獲取郵件的程序。參見fetchmail的主頁[http://www.catb.org/~esr/fetchmail](或者在Web上搜索“fetchmail”)。
GIMP The
GIMP (GNU Image Manipulation Program) is a full-featured paint, draw,
and image-manipulation program that can edit a huge variety of
graphical formats in sophisticated ways. Sources are available from the
GIMP home page [http://www.gimp.org/] (or search for "GIMP" on the Web).
GIMP GIMP(GNU圖象處理程序)是一個全功能的繪圖和圖象處理程序,它以精巧的方式編輯各種不同的圖象格式。從GIMP的主頁可以獲取可用的源碼[http://www.gimp.org/](或者在Web上搜索“GIMP”)。
mutt The
mutt mail user agent is the current best-of-breed among textbased Unix
electronic mail agents, with notably good support for MIME
(Multipurpose Internet Mail Extensions) and the use of privacy aids
such as PGP (Pretty Good Privacy) and GPG (GNU Privacy Guard). Source
code and executable binaries are available at the Mutt project site
[http://www.mutt.org].
mutt 在眾多基于文本的Unix電子郵件代理程序中,mutt郵件用戶代理程序是當前最好的一個。它對于MIME(Multipurpose Internet Mail Extensions)以及諸如PGP(Pretty Good Privacy)和GPG(GNU Privacy Guard)這樣的加密功能支持的非常好。在Mutt工程的站點[http://www.mutt.org]上,可以找到可用的源代碼和可執行二進制文件。
xmlto The
xmlto command renders DocBook and other XML documents in various output
formats, including HTML and text and PostScript. For sources and
documentation, see the xmlto project site
[http://cyberelk.net/tim/xmlto/].
xmlto xmlto命令用來把DocBook和那些XML文檔轉換成不同的格式,包括HTML、文本文件以及PostScript。在xmlto工程站點上可以找到源代碼和文檔[http://cyberelk.net/tim/xmlto/]。
To
minimize the amount of code the user needs to read to understand the
examples, we have tried to choose case studies that can be used more
than once, ideally to illustrate several different design principles
and practices. For this same reason, many of the examples are from my
projects. No claim that these are the best possible ones is implied,
merely that I find them sufficiently familiar to be useful for multiple
expository purposes.
為了盡量減少需要讀者去讀的代碼以及去理解的例子的數量,我們嘗試去挑選可以反復使用的例子來研究,以求完美地說明那幾個不同的設計原則和慣例。出于同樣的原因,許多例子來自我的工程。這并非暗示它們是最好的,只不過我覺得我對它們很熟悉,這會對各種目的的解釋有幫助。
Author’s Acknowledgements
致謝
The
guest contributors (Ken Arnold, Steven M. Bellovin, Stuart Feldman, Jim
Gettys, Steve Johnson, Brian Kernighan, David Korn, Mike Lesk, Doug
McIlroy, Marshall Kirk McKusick, Keith Packard, Henry Spencer, and Ken
Thompson) added a great deal of value to this book.. Doug McIlroy, in
particular, went far beyond the call of duty in the thoroughness of his
critique and the depth of his contributions, displaying the same care
and dedication to excellence which he brought to managing the original
Unix research group thirty years ago.
客串作者(Ken
Arnold, Steven M. Bellovin, Stuart Feldman, Jim Gettys, Steve Johnson,
Brian Kernighan, David Korn, Mike Lesk, Doug McIlroy, Marshall Kirk
McKusick, Keith Packard, Henry Spencer, 和Ken Thompson)為這本書增添了許多有價值的文章。特別是Doug McIlroy,他深刻的批評和極具深度的文章,遠遠超出了我邀請他時給出的任務,象三十年前管理最初的Unix研發組那樣,他給予了同樣的關注和奉獻。
Special
thanks go to Rob Landley and to my wife Catherine Raymond, both of whom
delivered intensive line-by-line critiques of manuscript drafts. Rob’s
insightful and attentive commentary actually inspired more than one
entire chapter in the final manuscript, and he had a lot to do with its
present organization and range; if he had written all the text he
pushed me to improve, I would have to call him a co-author. Cathy was
my test audience representing non-technical readers; to the extent this
book is accessible to people who aren’t already programmers, that’s
largely her doing.
特別感謝Rob Landley和我的妻子Catherine Raymond,他們均對本書的原稿逐行閱讀,并做出了深入的評價。Rob深刻且專注的評論比這最終手稿的一整章更令人激動,他在全文表述的組織和范圍方面作了大量的工作,如果所有推動我改進的文字全由他來撰寫,那我就不得不稱他為合著者。Cathy是我的試驗聽眾,代表了非技術讀者。為了拓展這本書的范圍,讓那些還不是程序員的人接受,有大量的工作要她去做。
This
book benefited from discussions with many other people over the five
years it took me to write it. Mark M. Miller helped me achieve
enlightenment about threads. John Cowan supplied some insights about
interface design patterns and drafted the case studies of wily and
VM/CMS, and Jef Raskin showed me where the Rule of Least Surprise comes
from. The UIUC System Architecture Group contributed useful feedback on
early chapters. The sections on What Unix Gets Wrong and Flexibility in
Depth were directly inspired by their review. Russell J. Nelson
contributed the material on Bernstein chaining in Chapter 7. Jay
Maynard contributed most of the material in the MVS case study in
Chapter 3. Les Hatton provided many helpful comments on the Languages
chapter and motivated the portion of Chapter 4 on Optimal Module Size.
David A. Wheeler contributed many perceptive criticisms and some
case-study material, especially in the Design part. Russ Cox helped
develop the survey of Plan 9. Dennis Ritchie corrected me on some
historical points about C.
在我寫書的這五年多里,和其他許多人的討論對本書的促成有很大幫助。Mark M. Miller啟發了我對線程的領悟。John Cowan對接口設計模式提供了一些見解,并為wily和VM/CMS的學習提供了實例。Jef Raskin向我說明了最小詫異原理是從哪里來的。UIUC系統架構小組對最初章節提供了有用的反饋。像“Unix之過”和“深入理解適應性”這樣的章節,其靈感就直接來源于他們的審閱。Russell J. Nelson為第7章的伯恩斯坦鏈表提供了材料。Jay Maynard為第3章中MVS的學習實例提供了大量的材料。在“語言”一章中,Les Hatton提供了許多有幫助的注解,并且促成了第4章關于最佳模塊尺寸的那部分。David A. Wheeler提供了許多有見地的批評和學習實例的資料,特別是在“設計”這部分。Russ Cox審定了本書第9次修改的計劃。Dennis Ritchie糾正了我在C的歷史上的一些觀點。
Hundreds
of Unix programmers, far too many to list here, contributed advice and
comments during the book’s public review period between January and
June of 2003. As always, I found the process of open peer review over
the Web both intensely challenging and intensely rewarding. Also as
always, responsibility for any errors in the resulting work remains my
own.
在本書2003年1月到6月這段公眾審閱期間,成百上千的Unix程序員提供了建議和注解,很遺憾這里不能一一列出。像往常一樣,我發現這種在Web上公開的同行審閱充滿了有趣的挑戰和獎賞。也是像往常一樣,最終著作中出現任何錯誤的責任都留給了我。
The
expository style and some of the concerns of this book have been
influenced by the design patterns movement; indeed, I flirted with the
idea of titling the book Unix Design Patterns. I didn’t, because I
disagree with some of the implicit central dogmas of the movement and
don’t feel the need to use all its formal apparatus or accept its
cultural baggage. Nevertheless, my approach has certainly been
influenced by Christopher Alexander’s work (especially The Timeless Way
of Building and A Pattern Language, and I owe the Gang of Four and
other members of their school a large debt of gratitude for showing me
how it is possible to use Alexander’s insights to talk about software
design at a high level without merely uttering vague and useless
generalities. Interested readers should see Design Patterns: Elements
of Reusable Object-Oriented Software [GangOfFour] for an introduction
to design patterns.
本書的說明風格以及關注點都受到了設計模式運動的影響。實際上,我曾經賣弄的想把這本書命名為“Unix設計模式”。最終我沒有如此做,因為對這場運動中的某些隱含的中心教義,我并不茍同。我并不覺得所有都需要使用它的索引形式,也不準備承擔這種文化帶來的負累。然而,我的方式當然受到了Christopher Alexander著作的影響(尤其是《建筑的永恒之道》和《模式語言》,在此我要感謝“四人幫”和他們學派的其他成員,感謝他們向我展示了如何用Alexander的觀點,在相當高的層次上討論軟件設計的可能性,而且沒有含混不請的言語和無用的概括。感興趣的讀者若想了解設計模式,應該看看《設計模式——可復用的面向對象軟件基礎》[GangOfFour])。
The
title of this book is, of course, a reference to Donald Knuth’s The Art
of Computer Programming. While not specifically associated with the
Unix tradition, Knuth has been an influence on us all.
當然,本書的書名借鑒了Donald Knuth的《計算機編程藝術》。雖然它和Unix傳統無明顯的關聯,但Knuth的確已經影響了我們每個人。
Editors
with vision and imagination aren’t as common as they should be. Mark
Taub is one; he saw merit in a stalled project and skillfully nudged me
into finishing it. Copy editors with a good ear for prose style and
enough ability to improve writing that isn’t like theirs are even less
common, but Mary Lou Nohr makes that grade. Jerry Votta seized on my
concept for the cover and made it look better than I had imagined. The
whole crew at Prentice-Hall gets high marks for making the editorial
and production process as painless as possible, and for cheerfully
accommodating my control-freak tendencies not just over the text but
deep into the details of the book’s visual design, art, and marketing.
有眼界和想象力的編輯不象他們看起來那么普通。Mark Taub就是這樣一個人。他看到了一個停工項目的價值,并且巧妙的推動我去完成它。文字編輯應該極不平常,他要能夠欣賞散文風格,并有足夠的能力去改善那些文字,也許他們看起來并不象,但Mary Lou Nohr做到了這種水平。對于封面,Jerry Votta領會了我的想法,并且做的比我想象的要好。在使這本書盡可能毫無痛楚的編寫和出版的過程中,Prentice出版社的全體人員做的很好。他們很愉快的接納了我古怪的操控傾向,這些不僅表現在文字上,而且深入到書籍感官上的設計,藝術,以及市場運作。