Unix philosophy
Encyclopedia : U : UN : UNI : 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:
- "This is the Unix philosophy:
- :Write programs that do one thing and do it well.
- :Write programs to work together.
- :Write programs to handle text streams, because that is a universal interface."
Of the three tenets, only the third is specific to Unix, though Unix developers often emphasized 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, though they can be easily viewed as points of a Unix philosophy:
- 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.
Mike Gancarz: The UNIX Philosophy
In 1994 Mike Gancarz (a member of the team that designed the X Window System), drawing 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. The UNIX Philosophy sums it up into 9 paramount prescripts:
- 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.
- 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
- Main article: Worse is better
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, such as sleep (10*60), 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 a very few number of programs - things like shells or text editors - that respond to job control keypresses - these programs could put small wrappers on their system calls and retry the call right away if this EINTR error was raised. Problem solved, in a simple way.
Because of the Unix Philosophy, for much of UNIX's early years it was the OS that crashed several times every day, while also being the OS with the shortest reboot times. [[Citing sources citation needed]]
Within a decade, because of the Unix Philosophy and resultant simplicity of the system, it was common for UNIX systems to outperform all other commercial operating systems with mean time to failure measured in months rather than hours.
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.
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
- "The UNIX philosophy basically involves giving you enough rope to hang yourself. And then a couple of feet more, just to be sure." - Unknown
See also
- Plan 9 from Bell Labs
- Pipes and filters
- The Elements of Style – One of the sources of inspiration for the Unix philosophy.
- UNIX-HATERS Handbook
- Software engineering
References
- [The Unix Programming Environment] by Brian Kernighan and Rob Pike, 1984
- [Notes on Programming in C], Rob Pike, September 21, 1989
- A Quarter Century of Unix, Peter H. Salus, Addison-Wesley, May 31, 1994 (ISBN 0201547775)
- [Philosophy] — from [The Art of Unix Programming], Eric S. Raymond, Addison-Wesley, September 17, 2003 (ISBN 0131429019)
- [Final Report of the Multics Kernel Design Project] by M. D. Schroeder, D. D. Clark, J. H. Saltzer, and D. H. Wells, 1977.
External links
From Wikipedia, the Free Encyclopedia. Original article here. Support Wikipedia by contributing or donating.
All text is available under the terms of the GNU Free Documentation License See Wikipedia Copyrights for details.
