The UNIX Philosophy

Source: Internet
Author: User
Document directory
  • Small programs are easy to understand
  • Small programs are easy to maintain
  • Small programs consume fewer system resources
  • Small programs are easier to combine with other tools
  • Three Systems
The UNIX Philosophy
Author:David Calvert


The UNIX Philosophy

FromThe UNIX PhilosophyBy Mike gancarz. Operating systems embody the philosophy of their creators.

  • MAC/OS is always Ally based with all options presented to the user
  • DoS attempts to create ''a taste of the mainframe''
  • Dec vms assumes users fear the machine and shocould be given a few powerful choices

The creators of UNIX assumed that its users wocould 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.Nine major tenetsOf 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 wrongly Ted 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

Translation 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 saved med 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 program 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.

TheFirst SystemIs built:

  • With the developers back against the wall (some constraint, usually time, forces the developer to try something drastic)
  • When there is no time to ''do it right''
  • Usually by a single person or at most a small group
  • And is a lean, mean, computing machine.

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.Second SystemIs:

  • Built by ''experts' using ideas proven in the first system
  • Designed by Committee
  • Fat and slow
  • Gains a great deal of specified cial acclaim

Despite their seconds comings, 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.

TheThird SystemIs:

  • Often built by people who have been ''burne'' by the second system
  • Often given a name change to disassociate it with the original obsolete technology
  • Still contains the original concept intact and is regarded as commonplace

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.

  • Next year's hardware will run faster -- performance may not be an issue in a short amount of time.
  • Don't spend too much time making programs run faster -- tuning a program is expensive and the gains are often not worth the time.
  • The most efficient way is rarely portable -- programs tied to hardware are rarely portable. hardware which is state-of-the-art when you create a program will soon be outdated and the worth of the program will drop quickly. it is better to have drivers for hardware which take advantage of advanced features but which also provide a consistent/stable programming interface.
  • Portable software has CES the need for user training.
  • Good programs will be imitated by others if you cannot port them.
Store numerical data in flat ASCII files

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

  • ASCII text is a common interchange format -- it is not the best or most efficient, but it is the most likely to be understood on a variety of machine. data which cannot be readily moved to another machine has limited value, and the act of converting data can be very expensive in time and money.
  • ASCII is easily read and edited -- specialized tools to manipulate the data are not required.
  • There already exists a wide array of text manipulation tools -- awk, cut, diff, grep, Head, Lex, more, Perl, sed, sort, tail, test, WC.
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.

  • Good programmers write good code; Great programmers ''borrow'' good code -- inconfigurating other people's modules and programs into your project has several advantages. it frees large amounts of development time, the obtained code is tested and debugged by the author, and it makes you look efficient.
  • Avoid the not-converted TED-Here syndrome -- there is no reason to reconstruct software which already exists. Most common applications are now standardized and produced by companies which specialize in their production.
  • Allow other people to use your code to leverage their work -- the most successful software is the one which appears on the most computers. proprietary software is usually more difficult to integrate into a system and if your product is too much trouble to use then competitors will develop a better version.
  • Automation everything -- simply put, take advantage of the computing environment to do as much work for you as possible. Learn the shortcuts which the shell and other commands provide.
Use shell scripts to increase leverage and portability
  • Shell scripts provide great amounts of leverage -- they provide you with the ability to use your previusly developed and tested programs with little effort.
  • Scripts save development time -- they are interpreted which eliminates compile time. However, they do not have a very good debugging system for scripts which lead to time wasted searching for a problem.
  • Scripts are more portable than 3gls -- and will likely work on any machine with little to no modification.
  • Resist the urge to rewrite shell scripts in a compiled language -- the components used by the shell have been developed by smart people and are probably more efficient than the ones you will write.
Avoid captive user interfaces

The problem with lower 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.

  • Cuis assume the user is human -- they do not allow the program to be run in a non-interactive mode which can be very inefficient for large throughput systems. similarly, they cannot be combined with other programs easily.
  • Cuis and big and difficult to write -- they often require large amounts of system resources, and are very complex.
  • Cuis don't scale well -- limitations are usually placed upon the operations which a Cui will allow you to perform to make the system easier to use. when too when instances of an operation must be repeated the interaction with the interface becomes a burden.
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 failed Ted 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 shocould be kept busy with parallel tasks whenever possible.

The sum of the parts is greater than the whole-- Merge 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.