Unix philosophy

Unix philosophy

The Unix philosophy is a set of cultural norms and philosophical approaches to developing software based on the experience of leading developers of the Unix operating system.

McIlroy: A Quarter Century of Unix

Doug McIlroy, the inventor of Unix pipes and one of the founders of the Unix tradition, summarized the philosophy as follows:Fact|date=September 2008

This is usually severely abridged to "Do one thing, do it well."

Of the three tenets, only the third is specific to Unix, though Unix developers often emphasize all three tenets more than other developers.

Pike: Notes on Programming in C

Rob Pike offers the following "rules" in "Notes on Programming in C" as programming maxims, [citeweb|title=Notes on Programming in C|url=http://www.lysator.liu.se/c/pikestyle.html|author=Rob Pike|accessdate=2008-07-08] though they can be easily viewed as points of a Unix philosophy:Fact|date=December 2007

*Rule 1: You cannot tell where a program is going to spend its time. Bottlenecks occur in surprising places, so do not try to second guess and put in a speed hack until you've proven that's where the bottleneck is.
*Rule 2: Measure. Do not tune for speed until you have measured, and even then don't unless one part of the code overwhelms the rest.
*Rule 3: Fancy algorithms are slow when n is small, and n is usually small. Fancy algorithms have big constants. Until you know that n is frequently going to be big, don't get fancy. (Even if n does get big, use Rule 2 first.)
*Rule 4: Fancy algorithms are buggier than simple ones, and they are much harder to implement. Use simple algorithms as well as simple data structures.
*Rule 5: Data dominates. If you have chosen the right data structures and organized things well, the algorithms will almost always be self-evident. Data structures, not algorithms, are central to programming.
*Rule 6: There is no Rule 6.

Pike's rules 1 and 2 restate Donald Knuth's [Knuth, Donald: [http://pplab.snu.ac.kr/courses/adv_pl05/papers/p261-knuth.pdf Structured Programming with Goto Statements] . "Computing Surveys" 6:4 (1974), 261–301. ] famous maxim "Premature optimization is the root of all evil." Ken Thompson rephrased Pike's rules 3 and 4 as "When in doubt, use brute force." Rules 3 and 4 are instances of the design philosophy KISS. Rule 5 was previously stated by Fred Brooks in "The Mythical Man-Month". Jon Bentley's "Programming Pearls" also has a chapter on the same design principle. Rule 5 is often shortened to "write stupid code that uses smart data", and is an instance of the guideline "If your data structures are good enough, the algorithm to manipulate them should be trivial." Rule 6 is merely a humorous reference to Monty Python's Bruces sketch.

Mike Gancarz: The UNIX Philosophy

In 1994 Mike Gancarz (a member of the team that designed the X Window System), drew on his own experience with Unix, as well as discussions with fellow programmers and people in other fields who depended on Unix, to produce "The UNIX Philosophy" which sums it up into 9 paramount precepts:

#"Small is beautiful."
#"Make each program do one thing well."
#"Build a prototype as soon as possible."
#"Choose portability over efficiency."
#"Store data in flat text files."
#"Use software leverage to your advantage."
#"Use shell scripts to increase leverage and portability."
#"Avoid captive user interfaces."
#"Make every program a filter."

The 10 lesser tenets are ones which are not universally agreed upon as part of the Unix philosophy, and in some cases, are hotly debated (Monolithic kernel vs. Microkernels):
#"Allow the user to tailor the environment."
#"Make operating system kernels small and lightweight."
#"Use lowercase and keep it short."
#"Save trees."
#"Silence is golden."
#"Think parallel."
#"The sum of the parts is greater than the whole."
#"Look for the 90-percent solution."
#"Worse is better."
#"Think hierarchically."

Worse is better

Richard P. Gabriel suggests that a key advantage of Unix was that it embodied a design philosophy he termed "Worse is better". In the "Worse is better" design style, simplicity of both the interface "and" the implementation is more important than any other attribute of the system — including correctness, consistency and completeness. Gabriel argues that this design style has key evolutionary advantages, though he questions the quality of some results.

For example, in the early days UNIX was a monolithic kernel (which means that user processes carried out kernel system calls all on the user stack). If a signal was delivered to a process while it was blocked on a long-term I/O in the kernel, then what should be done? Should the signal be delayed, possibly for a long time (maybe indefinitely) while the I/O completed? The signal handler could not be executed when the process was in kernel mode, with sensitive kernel data on the stack. Should the kernel back-out the system call, and store it, for replay and restart later, assuming that the signal handler completes successfully?

In these cases Ken Thompson and Dennis Ritchie favored simplicity over perfection. The UNIX system would occasionally return early from a system call with an error stating that it had done nothing - the "Interrupted System Call" - an error number 4 (EINTR) in today's systems. Of course the call had been aborted in order to call the signal handler. This could only happen for a handful of long-running system calls, i.e. read(), write(), open(), select(), etc. On the plus side, this made the I/O system many times simpler to design and understand. The vast majority of user programs were never affected because they didn't handle or experience signals other than SIGINT/^C and would die right away if one was raised. For the few other programs - things like shells or text editors that respond to job control keypresses - small wrappers could be added to system calls so as to retry the call right away if this EINTR error was raised. Problem solved, in a simple way.

Raymond: The Art of Unix Programming

Eric S. Raymond, in his book "The Art of Unix Programming", summarizes the Unix philosophy as the widely-used engineering philosophy, "Keep it Simple, Stupid" (KISS Principle). He then describes how he believes this overall philosophy is applied as a cultural Unix norm, although unsurprisingly it is not difficult to find severe violations of most of the following in actual Unix practice:

*Rule 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 to 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 transparency and simplicity.
*Rule of Representation: Fold knowledge into data so program logic can be stupid and robust.
*Rule of Least Surprise: In interface design, always do the least surprising thing.
*Rule of Silence: When a program has nothing surprising to say, it should say nothing.
*Rule of Repair: 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.

Many of these norms are accepted outside of the Unix community — if not when Unix first used them, then later on. Also, many were not unique or original to the Unix community. Nevertheless, adepts at Unix programming tend to accept a combination of these ideas as the foundation of the Unix style.

Controversy

It is controversial as to whether the Free Software Foundation's GNU work-alikes of standard Unix programs (such as diff, find, etc) follow the "Unix Philosophy" or misunderstand it. Certainly at least some Unix old timers claim the latter, since GNU tools are often substantially larger and more featureful than their Unix equivalents.

Already in 1983 Brian Kernighan and Rob Pike wrote a paper titled [http://harmful.cat-v.org/cat-v/ "Program Design in the UNIX Environment"] and gave a presentation on "UNIX Style, or cat -v Considered Harmful" criticizing BSD's expansion of the functionality of basic Unix tools like cat.

This trend only became much more significant with the advent of GNU and commercial Unix variants, and it is common for a single program to provide numerous features based on how it is called (for example, a program that both compresses and decompresses a file based on what name it is called by; an extreme example being the embedded Linux application BusyBox, which consolidates the most common command line functions into a single binary).

Quotes

*"Unix is simple. It just takes a genius to understand its simplicity." – Dennis Ritchie
*"UNIX was not designed to stop its users from doing stupid things, as that would also stop them from doing clever things." – Doug Gwyn
*"Unix never says 'please"'." – Rob Pike
*"Unix is user-friendly. It just isn't promiscuous about which users it's friendly with." – Steven King
*"Those who don't understand UNIX are condemned to reinvent it, poorly." – Henry Spencer

ee also

*Unix architecture
*Plan 9 from Bell Labs
*Pipes and filters
*The Elements of Style – One of the sources of inspiration for the Unix philosophy.
*The UNIX-HATERS Handbook
*Software engineering

References

*" [http://www-db-out.research.bell-labs.com/cm/cs/upe/ The Unix Programming Environment] " by Brian Kernighan and Rob Pike, 1984
* [http://www.lysator.liu.se/c/pikestyle.html "Notes on Programming in C"] , Rob Pike, September 21, 1989
*"A Quarter Century of Unix", Peter H. Salus, Addison-Wesley, May 31, 1994 (ISBN 0-201-54777-5)
* [http://www.faqs.org/docs/artu/philosophychapter.html "Philosophy"] — from [http://www.catb.org/~esr/writings/taoup "The Art of Unix Programming"] , Eric S. Raymond, Addison-Wesley, September 17, 2003 (ISBN 0-13-142901-9)
* [http://citeseer.ist.psu.edu/schroeder77final.html Final Report of the Multics Kernel Design Project] by M. D. Schroeder, D. D. Clark, J. H. Saltzer, and D. H. Wells, 1977.
* "The UNIX Philosophy", Mike Gancarz, ISBN 1555581234

Notes

External links

* [http://www.linfo.org/unix_philosophy.html The Unix Philosophy: A Brief Introduction] - by The Linux Information Project (LINFO)
* [http://www.joelonsoftware.com/articles/Biculturalism.html Joel on Software - Biculturalism]


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать курсовую

Look at other dictionaries:

  • Unix — (officially trademarked as UNIX, sometimes also written as Unix with small caps) is a computer operating system originally developed in 1969 by a group of AT T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Douglas McIlroy, and… …   Wikipedia

  • Unix-Philosophie — Die Unix Philosophie ist eine Menge von Regeln und Herangehensweisen bei der Software Entwicklung, die auf den Erfahrungen der führenden Unix Programmierer basieren. Inhaltsverzeichnis 1 McIlroy: A Quarter Century of Unix 2 Pike: Notes on… …   Deutsch Wikipedia

  • Unix architecture — A Unix architecture is a computer operating system system architecture that embodies the Unix philosophy. It may adhere to standards such as the Single UNIX Specification (SUS) or similar POSIX IEEE standard. No single published standard… …   Wikipedia

  • UNIX way — Философия UNIX  это набор культурных норм и философских подходов к разработке программного обеспечения, основанных на опыте ведущих разработчиков операционной системы Содержание 1 МакИлрой: Четверть века UNIX 2 Пайк: Стиль программирования на C …   Википедия

  • Unix way — Философия UNIX  это набор культурных норм и философских подходов к разработке программного обеспечения, основанных на опыте ведущих разработчиков операционной системы Содержание 1 МакИлрой: Четверть века UNIX 2 Пайк: Стиль программирования на C …   Википедия

  • Philosophie d'Unix — La philosophie d Unix est un ensemble de normes et une approche du développement de logiciels basée sur l expérience des principaux développeurs du système d exploitation Unix. Sommaire 1 McIlroy : Un Quart de siècle d Unix 2 Pike: Un mot… …   Wikipédia en Français

  • Philosophie d'UNIX — La philosophie d Unix est un ensemble de normes et une approche du développement de logiciels basée sur l expérience des principaux developpeurs du système d exploitation Unix. Sommaire 1 McIlroy: Un Quart de siècle d Unix 2 Pike: Un mot sur la… …   Wikipédia en Français

  • The Unix Programming Environment — is a textbook written by Brian W. Kernighan and Rob Pike, both of Bell Labs. It is considered an important and early book on the Unix operating system. Often considered the Bible , it is considered the most authoritative work on Unix. It was… …   Wikipedia

  • List of Unix utilities — This is a list of UNIX utilities as specified by IEEE Std 1003.1 2008, which is part of the Single UNIX Specification (SUS). These utilities can be found on UNIX Operating systems and most UNIX like operating systems. List IEEE Std 1003.1 2008… …   Wikipedia

  • dd (Unix) — In computing, dd is a common Unix program whose primary purpose is the low level copying and conversion of raw data. According to the manual page for Version 7 Unix,[1] it will convert and copy a file . It is used to copy a specified number of… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”