同步阅读进度,多语言翻译,过滤屏幕蓝光,评论分享,更多完整功能,更好读书体验,试试 阅读 ‧ 电子书库
The Art of Unix Programming
Next
Back to FAQS.ORG
The Art of Unix Programming
Eric Steven Raymond
Thyrsus Enterprises
牋牋<esr@thyrsus.com>
牋牋
Copyright � 2003 Eric S. Raymond
This book and its on-line version are distributed under the terms of the Creative Commons Attribution-NoDerivs 1.0 license, with the additional proviso that the right to publish it on paper for sale or other for-profit use is reserved to Pearson Education, Inc. A reference copy of this license may be found at http://creativecommons.org/licenses/by-nd/1.0/legalcode.
AIX, AS/400, DB/2, OS/2, System/360, MVS, VM/CMS, and IBM PC are trademarks of IBM. Alpha, DEC, VAX, HP-UX, PDP, TOPS-10, TOPS-20, VMS, and VT-100 are trademarks of Compaq. Amiga and AmigaOS are trademarks of Amiga, Inc. Apple, Macintosh, MacOS, Newton, OpenDoc, and OpenStep are trademarks of Apple Computers, Inc. ClearCase is a trademark of Rational Software, Inc. Ethernet is a trademark of 3COM, Inc. Excel, MS-DOS, Microsoft Windows and PowerPoint are trademarks of Microsoft, Inc. Java. J2EE, JavaScript, NeWS, and Solaris are trademarks of Sun Microsystems. SPARC is a trademark of SPARC international. Informix is a trademark of Informix software. Itanium is a trademark of Intel. Linux is a trademark of Linus Torvalds. Netscape is a trademark of AOL. PDF and PostScript are trademarks of Adobe, Inc. UNIX is a trademark of The Open Group.
The photograph of Ken and Dennis in Chapter�a> appears courtesy of Bell Labs/Lucent Technologies.
The epigraph on the Portability chapter is from the Bell System Technical Journal, v57 #6 part 2 (July-Aug. 1978) pp. 2021-2048 and is reproduced with the permission of Bell Labs/Lucent Technologies.
Revision History
Revision 1.0 19 September 2003 esr
This is the content that went to Addison-Wesley's printers.
Revision 0.4 5 February 2003 esr
Release for public review.
Revision 0.3 22 January 2003 esr
First eighteen-chapter draft. Manuscript walkthrough at Chapter 12. Limited release for early reviewers.
Revision 0.2 2 January 2003 esr
First manuscript walkthrough at Chapter 7. Released to Dmitry Kirsanov at AW production.
Revision 0.1 16 November 2002 esr
First DocBook draft, fifteen chapters. Languages rewritten to incorporate lots of feedback. Transparency, Modularity, Multiprogramming, Configuration, Interfaces, Documentation, and Open Source chapters released. Shipped to Mark Taub at AW.
Revision 0.0 1999 esr
Public HTML draft, first four chapters only.
Dedication
To Ken Thompson and Dennis Ritchie, because you inspired me.
Table of Contents
PrefaceWho Should Read This BookHow to Use This BookRelated ReferencesConventions Used in This BookOur Case StudiesAuthor's AcknowledgementsI. Context1. PhilosophyCulture? What Culture?The Durability of UnixThe Case against Learning Unix CultureWhat Unix Gets WrongWhat Unix Gets RightOpen-Source SoftwareCross-Platform Portability and Open StandardsThe Internet and the World Wide WebThe Open-Source CommunityFlexibility All the Way DownUnix Is Fun to HackThe Lessons of Unix Can Be Applied ElsewhereBasics of the Unix PhilosophyRule of Modularity: Write simple parts connected by clean interfaces.Rule of Clarity: Clarity is better than cleverness.Rule of Composition: Design programs to be connected with other programs.Rule of Separation: Separate policy from mechanism; separate interfaces from engines.Rule of Simplicity: Design for simplicity; add complexity only where you must.Rule of Parsimony: Write a big program only when it is clear by demonstration that nothing else will do.Rule of Transparency: Design for visibility to make inspection and debugging easier.Rule of Robustness: Robustness is the child of爐ransparency and simplicity.Rule of Representation: Fold knowledge into data, so爌rogram logic can be stupid and robust.Rule of Least Surprise: In interface design, always do the爈east surprising thing.Rule of Silence: When a program has nothing surprising to say, it should say nothing.Rule of Repair: Repair what you can — but when you must fail, fail noisily and as soon as possible.Rule of Economy: Programmer time is expensive; conserve it in preference to machine time.Rule of Generation: Avoid hand-hacking; write programs to write programs when you can.Rule of Optimization: Prototype before polishing. Get it working before you optimize it.Rule of Diversity: Distrust all claims for one true way.Rule of Extensibility: Design for the future, because it will be here sooner than you think.The Unix Philosophy in One LessonApplying the Unix PhilosophyAttitude Matters Too2. HistoryOrigins and History of Unix, 1969-1995Genesis: 1969–1971Exodus: 1971–1980TCP/IP and the Unix Wars: 1980-1990Blows against the Empire: 1991-1995Origins and History of the Hackers, 1961-1995At Play in the Groves of Academe: 1961-1980Internet Fusion and the Free Software Movement: 1981-1991Linux and the Pragmatist Reaction: 1991-1998The Open-Source Movement: 1998 and OnwardThe Lessons of Unix History3. ContrastsThe Elements of Operating-System StyleWhat Is the Operating System's Unifying Idea?Multitasking CapabilityCooperating ProcessesInternal BoundariesFile Attributes and Record StructuresBinary File FormatsPreferred User Interface StyleIntended AudienceEntry Barriers to DevelopmentOperating-System ComparisonsVMSMacOSOS/2Windows NTBeOSMVSVM/CMSLinuxWhat Goes Around, Comes AroundII. Design4. ModularityEncapsulation and Optimal Module SizeCompactness and OrthogonalityCompactnessOrthogonalityThe SPOT RuleCompactness and the Strong Single CenterThe Value of DetachmentSoftware Is a Many-Layered ThingTop-Down versus Bottom-UpGlue LayersCase Study: C Considered as Thin GlueLibrariesCase Study: GIMP PluginsUnix and Object-Oriented LanguagesCoding for Modularity5. TextualityThe Importance of Being TextualCase Study: Unix Password File FormatCase Study: .newsrc FormatCase Study: The PNG Graphics File FormatData File MetaformatsDSV StyleRFC 822 FormatCookie-Jar FormatRecord-Jar FormatXMLWindows INI FormatUnix Textual File Format ConventionsThe Pros and Cons of File CompressionApplication Protocol DesignCase Study: SMTP, the Simple Mail Transfer ProtocolCase Study: POP3, the Post Office ProtocolCase Study: IMAP, the Internet Message Access ProtocolApplication Protocol MetaformatsThe Classical Internet Application MetaprotocolHTTP as a Universal Application ProtocolBEEP: Blocks Extensible Exchange ProtocolXML-RPC, SOAP, and Jabber6. TransparencyStudying CasesCase Study: audacityCase Study: fetchmail's -v optionCase Study: GCCCase Study: kmailCase Study: SNGCase Study: The Terminfo DatabaseCase Study: Freeciv Data FilesDesigning for Transparency and DiscoverabilityThe Zen of TransparencyCoding for Transparency and DiscoverabilityTransparency and Avoiding OverprotectivenessTransparency and Editable RepresentationsTransparency, Fault Diagnosis, and Fault RecoveryDesigning for Maintainability7. MultiprogrammingSeparating Complexity Control from Performance TuningTaxonomy of Unix IPC MethodsHanding off Tasks to Specialist ProgramsPipes, Redirection, and FiltersWrappersSecurity Wrappers and Bernstein ChainingSlave ProcessesPeer-to-Peer Inter-Process CommunicationProblems and Methods to AvoidObsolescent Unix IPC MethodsRemote Procedure CallsThreads — Threat or Menace?Process Partitioning at the Design Level8. MinilanguagesUnderstanding the Taxonomy of LanguagesApplying MinilanguagesCase Study: sngCase Study: Regular ExpressionsCase Study: GladeCase Study: m4Case Study: XSLTCase Study: The Documenter's Workbench ToolsCase Study: fetchmail Run-Control SyntaxCase Study: awkCase Study: PostScriptCase Study: bc and dcCase Study: Emacs LispCase Study: JavaScriptDesigning MinilanguagesChoosing the Right Complexity LevelExtending and Embedding LanguagesWriting a Custom GrammarMacros — Beware!Language or Application Protocol?9. GenerationData-Driven ProgrammingCase Study: asciiCase Study: Statistical Spam FilteringCase Study: Metaclass Hacking in fetchmailconfAd-hoc Code GenerationCase Study: Generating Code for the ascii DisplaysCase Study: Generating HTML Code for a Tabular List10. ConfigurationWhat Should Be Configurable?Where Configurations LiveRun-Control FilesCase Study: The .netrc FilePortability to Other Operating SystemsEnvironment VariablesSystem Environment VariablesUser Environment VariablesWhen to Use Environment VariablesPortability to Other Operating SystemsCommand-Line OptionsThe -a to -z of Command-Line OptionsPortability to Other Operating SystemsHow to Choose among the MethodsCase Study: fetchmailCase Study: The XFree86 ServerOn Breaking These Rules11. InterfacesApplying the Rule of Least SurpriseHistory of Interface Design on UnixEvaluating Interface DesignsTradeoffs between CLI and Visual InterfacesCase Study: Two Ways to Write a Calculator ProgramTransparency, Expressiveness, and ConfigurabilityUnix Interface Design PatternsThe Filter PatternThe Cantrip PatternThe Source PatternThe Sink PatternThe Compiler PatternThe ed patternThe Roguelike PatternThe ‘Separated Engine and Interface’ PatternThe CLI Server PatternLanguage-Based Interface PatternsApplying Unix Interface-Design PatternsThe Polyvalent-Program PatternThe Web Browser as a Universal Front EndSilence Is Golden12. OptimizationDon't Just Do Something, Stand There!Measure before OptimizingNonlocality Considered HarmfulThroughput vs. LatencyBatching OperationsOverlapping OperationsCaching Operation Results13. ComplexitySpeaking of ComplexityThe Three Sources of ComplexityTradeoffs between Interface and Implementation ComplexityEssential, Optional, and Accidental ComplexityMapping ComplexityWhen Simplicity Is Not EnoughA Tale of Five EditorsedviSamEmacsWilyThe Right Size for an EditorIdentifying the Complexity ProblemsCompromise Doesn't WorkIs Emacs an Argument against the Unix Tradition?The Right Size of SoftwareIII. Implementation14. LanguagesUnix's Cornucopia of LanguagesWhy Not C?Interpreted Languages and Mixed StrategiesLanguage EvaluationsCC++ShellPerlTclPythonJavaEmacs LispTrends for the FutureChoosing an X Toolkit15. ToolsA Developer-Friendly Operating SystemChoosing an EditorUseful Things to Know about viUseful Things to Know about EmacsThe Antireligious Choice: Using BothSpecial-Purpose Code Generatorsyacc and lexCase Study: Glademake: Automating Your RecipesBasic Theory of makemake in Non-C/C++ DevelopmentUtility ProductionsGenerating MakefilesVersion-Control SystemsWhy Version Control?Version Control by HandAutomated Version ControlUnix Tools for Version ControlRuntime DebuggingProfilingCombining Tools with EmacsEmacs and makeEmacs and Runtime DebuggingEmacs and Version ControlEmacs and ProfilingLike an IDE, Only Better16. ReuseThe Tale of J. Random NewbieTransparency as the Key to ReuseFrom Reuse to Open SourceThe Best Things in Life Are OpenWhere to Look?Issues in Using Open-Source SoftwareLicensing IssuesWhat Qualifies as Open SourceStandard Open-Source LicensesWhen You Need a LawyerIV. Community17. PortabilityEvolution of CEarly History of CC StandardsUnix StandardsStandards and the Unix WarsThe Ghost at the Victory BanquetUnix Standards in the Open-Source WorldIETF and the RFC Standards ProcessSpecifications as DNA, Code as RNAProgramming for PortabilityPortability and Choice of LanguageAvoiding System DependenciesTools for PortabilityInternationalizationPortability, Open Standards, and Open Source18. DocumentationDocumentation ConceptsThe Unix StyleThe Large-Document BiasCultural StyleThe Zoo of Unix Documentation Formatstroff and the Documenter's Workbench ToolsTeXTexinfoPODHTMLDocBookThe Present Chaos and a Possible Way OutDocBookDocument Type DefinitionsOther DTDsThe DocBook ToolchainMigration ToolsEditing ToolsRelated Standards and PracticesSGMLXML-DocBook ReferencesBest Practices for Writing Unix Documentation19. Open SourceUnix and Open SourceBest Practices for Working with Open-Source DevelopersGood Patching PracticeGood Project- and Archive-Naming PracticeGood Development PracticeGood Distribution-Making PracticeGood Communication PracticeThe Logic of Licenses: How to Pick OneWhy You Should Use a Standard LicenseVarieties of Open-Source LicensingMIT or X Consortium LicenseBSD Classic LicenseArtistic LicenseGeneral Public LicenseMozilla Public License20. FuturesEssence and Accident in Unix TraditionPlan 9: The Way the Future WasProblems in the Design of UnixA Unix File Is Just a Big Bag of BytesUnix Support for GUIs Is WeakFile Deletion Is ForeverUnix Assumes a Static File SystemThe Design of Job Control Was Badly BotchedThe Unix API Doesn't Use Exceptionsioctl2 and fcntl2 Are an EmbarrassmentThe Unix Security Model May Be Too PrimitiveUnix Has Too Many Different Kinds of NamesFile Systems Might Be Considered HarmfulTowards a Global Internet Address SpaceProblems in the Environment of UnixProblems in the Culture of UnixReasons to BelieveA. Glossary of AbbreviationsB. ReferencesC. ContributorsD. Rootless RootEditor's IntroductionMaster Foo and the Ten Thousand LinesMaster Foo and the Script KiddieMaster Foo Discourses on the Two PathsMaster Foo and the MethodologistMaster Foo Discourses on the Graphical User InterfaceMaster Foo and the Unix ZealotMaster Foo Discourses on the Unix-NatureMaster Foo and the End UserList of Figures2.1. The PDP-7.3.1. Schematic history of timesharing.4.1. Qualitative plot of defect count and density vs. module size.4.2. Caller/callee relationships in GIMP with a plugin loaded.6.1. Screen shot of audacity.6.2. Screen shot of kmail.6.3. Main window of a Freeciv game.8.1. Taxonomy of languages.11.1. The xcalc GUI.11.2. Screen shot of the original Rogue game.11.3. The Xcdroast GUI.11.4. Caller/callee relationships in a polyvalent program.13.1. Sources and kinds of complexity.18.1. Processing structural documents.18.2. Present-day XML-DocBook toolchain.18.3. Future XML-DocBook toolchain with FOP.List of Tables8.1. Regular-expression examples.8.2. Introduction to regular-expression operations.14.1. Language choices.14.2. Summary of X Toolkits.List of Examples5.1. Password file example.5.2. A .newsrc example.5.3. A fortune file example.5.4. Basic data for three planets in a record-jar format.5.5. An XML example.5.6. A .INI file example.5.7. An SMTP session example.5.8. A POP3 example session.5.9. An IMAP session example.6.1. An example fetchmail -v transcript.6.2. An SNG Example.7.1. The pic2graph pipeline.8.1. Glade Hello, World.8.2. A sample m4 macro.8.3. A sample XSLT program.8.4. Taxonomy of languages — the pic source.8.5. Synthetic example of a fetchmailrc.8.6. RSA implementation using dc.9.1. Example of fetchmailrc syntax.9.2. Python structure dump of a fetchmail configuration.9.3. copy_instance metaclass code.9.4. Calling context for copy_instance.9.5. ascii usage screen.9.6. Desired output format for the star table.9.7. Master form of the star table.10.1. A .netrc example.10.2. X configuration example.18.1. groff1 markup example.18.2. man markup example.19.1. tar archive maker production.
Next
燩reface
请支持我们,让我们可以支付服务器费用。
使用微信支付打赏