17 programming principles in the art of Unix programming

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

UArt of Nix programming17 philosophical principles of programming

Design of high standards - Developer

Translator: July January 13, 2011.

Reference: The Art of Unix Programming
By Eric Steven Raymond

The blogger Description: This paper is based on a unix programming book art of English version, the first chapter section, do translation.
In the process of translation, with reference to the Chinese Version (Jiang Hong.). If you have a better translation opinions, welcome message proposal.

A, a unix programming book art paper
This book introduces the Unix system in the field of design and development philosophy, ideological and cultural system, principles and experience,
By recognized masters Unix programming, the open source movement leader of Eric S. Raymond to years of writing and.

Including the Unix designers, many experts in the field is a valuable contribution to the content of the book.
This book covers the design and implementation of software development, community culture, wide coverage, content depth, fully demonstrates the great depth of experience and wisdom.

Two, the UNIX philosophy foundation
The inventor of the UNIX UNIX pipeline, one of the founders of McIlroy in traditional Doug <<UNIX > > in the 1/4 century;,
Summed up the UNIX Philosophy:
A program written by only one thing to do, and do a good job. A program written to cooperate,
At the same time, to be able to handle the flow of text, because that is the most common (or fundamental) interface.

Rob Pike, C language is one of the greatest, he in the <<Notes on C Programming> > a Book,
From the different perspective, discusses the principles of the UNIX Philosophy:
Principle 1: you can't judge the program will take its run time where. Bottleneck often show up in unexpected places,
So, don't be in a hurry to find a random place, just change a pass, unless you have indeed found and confirmed that the crux of the problem.

Principle 2: measure. Before you haven't program code for the overall measure, especially before haven't found the most time-consuming,
Thinking about the optimization speed naive not to.

Principle 3: fancy algorithms are usually more hours in the N, very slow. Because of constant fancy and unrealistic, the complexity of the algorithm greatly.
Unless you can be sure n is great, not to venture, use fancy algorithm (even if the n is very big, but also to give priority to principle 2).

Principle 4: fancy algorithm more easily than the simple and practical algorithm error (Bug), and more difficult to achieve (maintenance). So, if you have not.,
Minimize the use of simple algorithm, with a simple data structure.

The overriding principle of 5: data. If, you have chosen the right data structures and all organizations be arranged in good order,
So it is self-evident, correct and efficient algorithm. Programming the core in the data structure, and not in the algorithm. (on behalf of Rob Pike's point of view).

Ken Thompson, The original version of UNIX designers, and practitioners, in the face of the Rob Pike Principle 4, said:
If you are unsure, is exhaustive.

Three, the UNIX philosophy principle
The UNIX philosophy of art more, not by the sages of oral described, but whatever they do, including UNIX itself, reflected

The. On the whole, can be summarized as the following17Principles of:

1, Rule of Modularity: Write simple parts connected by clean interfaces.
1, Module principle: try to use simple interface and simple assembly.
As Brian Kernighan, once said, " the essence of computer programming is to control (reduce) program complexity".
Design a program, debugging error often accounts for most of the development time, finally getting a shot of available system,
It is full of wit of the design results, still be inferior to saying is the result bumps along the way.

The preparation of complex and large software, the only way is to control, reduce, and the overall complexity, with clear interface module combination into a complex software.

This is the principle, module, or as a modular, between each module, reduce the coupling, so independent, do not change, a place, and use the whole body.

2, Rule of Clarity: Clarity is better than cleverness.
2, Principle of clarity: clarity is better than cleverness.
Written procedures, is to give the computer execution, but to the people, such as the late maintenance program.
A hard to understand the program, will enable the late maintenance, modification, or performance, algorithm optimization work, will be blocked.

So, write the program time, always keep in mind: write clear and easy procedure, add good useful annotations.
For man, which is benefit.

3, Rule of Composition: Design programs to be connected to other programs.
3, Combination principle: the design, to consider the combination of.
In order to let the program can communicate with each other, let the program with a combination of independent modules, each other.

4, Rule of Separation: Separate policy from mechanism; separate interfaces from engines.
4, The separation principle: strategy and mechanism of separation, interfaces from engines.
If the same mechanism, strategy, mixed into a ball, there are two negative effects will be,
A strategy, is very rigid, it is difficult to adapt to the user demand change; two, at the same time, will also mean that any policy changes will most likely shake to the whole mechanism.

But, instead, the strategy and mechanism, both isolated words, may in time to try new strategies, not to break the original mechanism.
And, I can easily write test cases for the mechanism of good.

5, Rule of Simplicity: Design for simplicity; add complexity only where you must.
5, Simplicity principle: the design as simple as possible, complexity can low is low.
Some programmers, often like Dao some perplexing things, to display the superiority, or to satisfy his vanity.
Programmers are very clever, because of their own have enough ability to get along well with some complex and abstract things, and proud, this no ground for blame.

But at the same time, they play with complex, kick up a cloud of dust after correction, will feel aversion program debugging.
Because of the cost, kick up a cloud of dust, is a costly waste.

Therefore, the best way is, concise for the beauty. In all, simplicity first.

6, Rule of Parsimony: Write a big program only when it is clear by demonstration that

nothing else will do.
6, Mean principle: unless do, otherwise, not to write a big program.
This, keep up with the fifth point almost, with concise for the beauty, do not write the huge and complicated procedures.

7, Rule of Transparency: Design for visibility to make inspection and debugging easier.
7, The transparent principle: the design should be transparent, in order to review and adjustment.
Considering the transparency, obvious, simple.

8, Rule of Robustness: Robustness is the child of transparency and simplicity.
8, Rule of robustness: robust program source in transparency and simplicity.
The program more concise, more transparent, more robust program.

9, Rule of Representation: Fold knowledge into data so program logic can be stupid and

9, Said (method) principle: Fold knowledge into data, in order to logical structure simple and robust.
Modeling, in order to clear logical structure.

10, Rule of Least Surprise: In interface design, always do the least surprising thing.
10, Popular principles: the interface design, to avoid the new in order to be different.
The procedure quality by the user to judge, the most simple, the most popular program, is often the most popular with users of the program.

11, Rule of Silence: When a program has nothing surprising to say, it should say nothing.
11, Rule of silence: if a program is not what picky, then keep silence.
Don't have extra miscellaneous parts, as far as possible simple, redundant functions do not need, do not have.

12, Rule of Repair: When you must fail, fail noisily and as soon as possible.
12, Remedial principle: abnormal, quit immediately and appropriate given enough error messages.
As far as possible, let the program in an easily diagnosed incorrectly terminated.

13, Rule of Economy: Programmer time is expensive; conserve it in preference to machine

13, Economic principle: would rather spend the machine, don't waste a second programmer.
Remember, the programmer's time is precious, not without wasting a minute.

14, Rule of Generation: Avoid hand-hacking; write programs to write programs when you can.
14, Generating principle: avoid manual hack (literal translation), as far as possible the program, let the program to generate program.
Program the more simple, more easily make the designer.

15, Rule of Optimization: Prototype before polishing. Get it working before you optimize it.
15, Rule of Optimization: sculpture before model, ran before, must first learn to walk.
The first prototype, and then carved. Before the optimization, first make sure that can be used. Otherwise, all the wonderful optimization, all is in vain.
Or like extreme programming, master Kent Beck said, first for operation, and then seek the right, finally for fast.

Don't blindly to consider those so-called petty profits increase efficiency. Premature optimization, often become the root of all evil.

16, Rule of Diversity: Distrust all claims for "one true way".
16, Rule of diversity: never going to believe what the so-called golden rule " " expression.
Even the best software, and are often limited to the designer's imagination.
Einstein once said that one sentence, the world is not the lack of technology, but imagination.

No one can be wise to put all the things, can be predicted in advance to arrange.

17, Rule of Extensibility: Design for the future, because it will be here sooner than you

17, Extension principle: the design should make the in the future, because sometimes the future than the imagination of the fast.
Never think yourself design is perfect, can terminate, or enhance the optimization.

So, for the data type, and the code behind; extensible space, later you will find, original choice is wise.

Therefore, the design to the in the future.
ok, More please reference book. Finish.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Rita at December 15, 2013 - 6:11 PM