The Unix Philosophy



The UNIX Philosophy

From The UNIX Philosophy by Mike Gancarz. Operating systems embody the philosophy of their creators. The creators of Unix assumed that its users would be computer literate. Little effort was placed into making it accessible to novices. ``If you can't understand it, then you don't belong here.''

A Little History

Ken Thompson wrote the first Unix at Bell Labs in 1969. It ran on a DEC PDP-7 and was based upon Multics, one of the first time sharing (non-batch) operating systems. In 1972 he rewrote it in a portable language called B which was later modified by Dennis Ritchie to become C in 1973.

The UNIX Philosophy

The philosophy is a result of more than twenty years of software development and has grown from the UNIX community instead of being enforced upon it. It is a defacto-style of software development. The nine major tenets of the UNIX Philosophy are:
  1. small is beautiful
  2. make each program do one thing well
  3. build a prototype as soon as possible
  4. choose portability over efficiency
  5. store numerical data in flat files
  6. use software leverage to your advantage
  7. use shell scripts to increase leverage and portability
  8. avoid captive user interfaces
  9. make every program a filter

The Ten Lesser Tenets

  1. allow the user to tailor the environment
  2. make operating system kernels small and lightweight
  3. use lower case and keep it short
  4. save trees
  5. silence is golden
  6. think parallel
  7. the sum of the parts if greater than the whole
  8. look for the ninety percent solution
  9. worse is better
  10. think hierarchically

Small is Beautiful

If you are writing a program, start small and keep it small. Strive for simplicity and keep the system components as small as possible. Small programs may not do very much themselves, but become quite powerful when combined with each other.

In most traditional software a large portion of the code is devoted to something other than the task which that program is intended. This can lead to greater complexity.

Example: A copy command can easily perform twelve different tasks, only one of which is copying a file.

Small Programs are Easy to Understand

Small programmes contain only a few algorithms and keep the focus on a single problem. Larger programs tend towards complexity and are difficult to understand. The sheer size of the program can make it unmanageable for the programmer.

Small Programs are Easy to Maintain

Ease of understanding translates to easier maintenance.

Small Programs Consume Fewer System Resources

Less memory is required to run, less time is required to load, and less disk space is needed to store small programs.

Small Programs are Easier to Combine with Other Tools

Monolithic programs are assumed to contain all of the features necessary for an application. This mistakenly assumes that the future of the software isn't going to be much different from today. The idea behind focused programs is that when new trends develop, new small programs can be built to take advantage of them.

Make Each Program Do One Thing Well

This compliments the tenet of smallness. Focusing on a single task helps the developer to avoid being caught-up in details which are unrelated to the programs primary function. Tasks like input and output formatting can be performed in other programs which are developed for such tasks.

Build a Prototype as Soon as Possible

This tenet developed because it is extremely difficult to predict the results of a software development project without first developing the software.

This idea runs counter to many software engineering methods which state that a majority of the design must be completed before any code is written. It is really an extreme form of prototyping and is intended to aid in the development of the final system. Prototyping is used to learn about the system and to reduce the risk of major problems in the final system.

Three Systems

Software systems tend to have three stages in their life. The UNIX Philosophy assumes that this must be the case and suggests that an iterative design method is therefore essential.

The First System is built:

The first system usually contains a concept which is innovative and attracts the attention of other developers.

The second system is built when the first system has been seen as something good. The Second System is:

Despite their shortcomings, second systems usually have enough momentum to keep other contenders for the market from succeeding. The third system appears after people become disenchanted with their second system.

The Third System is:

The third system combines the best characteristics of the first and second systems. Its developers are given the time to properly develop the system.

Choose Portability over Efficiency

Software which is written specifically for one architecture is limited in its marketability and is usually quite difficult to port.

Store Numerical Data in Flat ASCII Files

All numerical data should be stored as ASCII text. No special file formats should be used. Data should appear as stream of bytes separated by newline characters.

Use Software Leverage to Your Advantage

Only so much can be done by one individual or group and a great deal has already been done.

Use Shell Scripts to Increase Leverage and Portability

Avoid Captive User Interfaces

The problem with many small programs is that it is difficult to learn about them all and users become confused. In order to make them more easy to use developers often bind them together through a single interface. Captive User Interfaces (CUIs) prevent users from interacting with the system once the have started the application.

Make Every Program A Filter

Every program is a filter in the sense that it produces an output given an input. If the action of filtering is so common then it makes sense to build software which takes advantage of it.

If programmes are capable of producing output given a stream of input then they have the added flexibility of being used in non-interactive systems.

The Lesser Tenets

Allow the user to tailor the environment -- allows the user to build an environment they are comfortable with. The drawback is the imposing amount of knowledge required to learn about the environment.

Make operating system kernels small and lightweight -- keeping the kernel devoted to the basic system services makes the system robust. Added features do not have the ability to halt the system if they are not working correctly.

Use lower case and keep it short -- lower case provides more visual cues to the reader which makes it easier to read and correspondingly less stressful.

Save trees -- data which is in a form that cannot be manipulated is near useless. Keeping data online allows for more processing to be done with it.

Silence is golden -- Unix provides ``just the facts'' when executing a program and does not address the user in a conversational tone. If a program says nothing (ls on an empty directory) then it means there is nothing.

Think parallel -- the CPU is seldomly busy for long and should be kept busy with parallel tasks whenever possible.

The sum of the parts is greater than the whole -- many small components can be combined to produce a greater program.

Look for the ninety percent solution -- it is easier to solve most problems by ignoring the most difficult ten percent. If operations in a program are costly and will be used by few people it is better to drop them from the project.

Worse is better -- the niche which Unix occupied was never on the ``industrial strength'' systems of the world. It grew to fill the low end minicomputer and later workstation market.

Think hierarchically -- the method of ordering items from a more general description to a very specific one is a powerful way to arrange things.
Author: David Calvert
Date of Last Update: June 7, 1996.