Користувач:Phrippy/пісочниця

Матеріал з Вікіпедії — вільної енциклопедії.
Перейти до навігації Перейти до пошуку

Філософія Unix, заснована Кеном Томпсоном, являє собою набір культурних норм і філософських підходів до мінімалістичної, модульної розробки програмного забезпечення. Вона базується на досвіді провідних розробників операційної системи Unix. Ранні розробники Unix надавали важливе значення поняттям модульності і повторного використання коду при розробці програмного забезпечення, започаткували рух "інструментальне програмне забезпечення". З часом, провідні розробники Unix (і програм, які запускались на ній) встановили набір культурних норм в розробці програмного забезпечення, норм, які стали такими ж важливими і впливовими, як і сама Unix; вони і були названі "філософією Unix".

Філософія Unix наголошує на написанні простого, короткого, чистого, модульного та розширюваного коду, який буде легко підтримуватись і повторно використовуватись іншими розробниками, але не лише тими, хто його написав. Філософія Unix сприяє компонованості, навідміну від монолітного дизайну.

Походження

[ред. | ред. код]

Дуглас Макілрой приписав філософію обʼєднання "маленьких, точних інструментів"[1]для виконання більших задач Кену Томпсону, одному з творців Unix.

Розроблення конвеєру формалізувало існуючі принципи введення-виведення у філософії Unix версії 3 зі старішим програмним забезпеченням, переписаним для узгодження. Раніше visible in early утиліти, такі як wc, cat, та uniq, Макілрой згадував Томпсоновий grep як "інструмент, що безповоротно вкорінений в світогляд" операційної системи, з пізнішими утилітами накшталт tr, m4, та sed, що імітують роботу grep по трансформації вхідного потоку.[2]

"Правда про Unix: інтерфейс користувача - жахливий"[3] was a 1981 criticism of the design philosophy published in Datamation. It was written by Don Norman, who had a background in cognitive science and was the key proponent of the then-current philosophy of cognitive engineering,[4] apparently focused on how engineers comprehend and form a personal cognitive model of a system.

The UNIX Programming Environment

[ред. | ред. код]
Rob Pike, co-author of The UNIX Programming Environment

In their preface to the 1984 book, The UNIX Programming Environment, Brian Kernighan and Rob Pike, both from Bell Labs, give a brief description of the Unix design and the Unix philosophy:[5]

The authors further write that their goal for this book is "to communicate the UNIX programming philosophy."[5]

Program Design in the UNIX Environment

[ред. | ред. код]
Brian Kernighan has written at length about the Unix philosophy

In October 1984, Brian Kernighan and Rob Pike published a paper called Program Design in the UNIX Environment. In this paper, they criticize the accretion of program options and features found in some newer Unix systems such as 4.2BSD and System V, and explain the Unix philosophy of software tools, each performing one general function:[6]

The authors contrast Unix tools such as cat, with larger program suites used by other systems.[6]

Doug McIlroy on Unix programming

[ред. | ред. код]
Doug McIlroy (left) with Dennis Ritchie

McIlroy, then head of the Bell Labs CSRC (ComHuylg Sciences Research Center), and inventor of the Unix pipe,[7] summarized the Unix philosophy as follows:[8]

Beyond these statements, he has also emphasized simplicity and minimalism in Unix programming:[9]

Conversely, McIlroy has criticized modern Linux as having software bloat, remarking that, "adoring admirers have fed Linux goodies into a disheartening state of obesity."[10] He contrasts this with earlier approach taken at Bell Labs when developing and revising Research Unix:[11]

Do One Thing and Do It Well

[ред. | ред. код]

As stated by McIlroy, and generally accepted throughout the Unix community, Unix programs have always been expected to follow the concept of DOTADIW, or "Do One Thing and Do It Well." Sources for the acronym DOTADIW are limited throughout the internet, but is discussed at length during the development and packaging of new operating systems, especially in the Linux community. There has been a point of great contention during the Linux systemd debates of 2014–2015, and especially in the Debian community.[12]

Patrick Volkerding, the project lead of Slackware Linux, invoked this design principle in a criticism of the systemd architecture, stating that, "attempting to control services, sockets, devices, mounts, etc., all within one daemon flies in the face of the UNIX concept of doing one thing and doing it well."[13]

Eric Raymond’s 17 Unix Rules

[ред. | ред. код]

In his book The Art of Unix Programming that was first published in 2003,[14] Eric S. Raymond, an American programmer and open source advocate, summarizes the Unix philosophy as KISS Principle of "Keep it Simple, Stupid."[15] He provides a series of design rules:[16]

Rule of Modularity
Developers should build a program out of simple parts connected by well defined interfaces, so problems are local, and parts of the program can be replaced in future versions to support new features. This rule aims to save time on debugging code that is complex, long, and unreadable.
Rule of Clarity
Developers should write programs as if the most important communication is to the developer, including themself, who will read and maintain the program rather than the computer. This rule aims to make code readable and comprehensible for whoever works on the code in future.
Rule of Composition
Developers should write programs that can communicate easily with other programs. This rule aims to allow developers to break down projects into small, simple programs rather than overly complex monolithic programs.
Rule of Separation
Developers should separate the mechanisms of the programs from the policies of the programs; one method is to divide a program into a front-end interface and back-end engine that interface communicates with. This rule aims to let policies be changed without destabilizing mechanisms and consequently reducing the number of bugs.
Rule of Simplicity
Developers should design for simplicity by looking for ways to break up program systems into small, straightforward cooperating pieces. This rule aims to discourage developers’ affection for writing “intricate and beautiful complexities” that are in reality bug prone programs.
Rule of Parsimony
Developers should avoid writing big programs. This rule aims to prevent overinvestment of development time in failed or suboptimal approaches caused by the owners of the program’s reluctance to throw away visibly large pieces of work. Smaller programs are not only easier to optimize and maintain; they are easier to delete when deprecated.
Rule of Transparency
Developers should design for visibility and discoverability by writing in a way that their thought process can lucidly be seen by future developers working on the project and using input and output formats that make it easy to identify valid input and correct output. This rule aims to reduce debugging time and extend the lifespan of programs.
Rule of Robustness
Developers should design robust programs by designing for transparency and discoverability, because code that is easy to understand is easier to stress test for unexpected conditions that may not be foreseeable in complex programs. This rule aims to help developers build robust, reliable products.
Rule of Representation
Developers should choose to make data more complicated rather than the procedural logic of the program when faced with the choice, because it is easier for humans to understand complex data compared with complex logic. This rule aims to make programs more readable for any developer working on the project, which allows the program to be maintained.[17]
Rule of Least Surprise
Developers should design programs that build on top of the potential users' expected knowledge; for example, ‘+’ in a calculator program should always mean 'addition'. This rule aims to encourage developers to build intuitive products that are easy to use.
Rule of Silence
Developers should design programs so that they do not print unnecessary output. This rule aims to allow other programs and developers to pick out the information they need from a program's output without having to parse verbosity.
Rule of Repair
Developers should design programs that fail in a manner that is easy to localize and diagnose or in other words “fail noisily”. This rule aims to prevent incorrect output from a program from becoming an input and corrupting the output of other code undetected.
Rule of Economy
Developers should value developer time over machine time, because machine cycles today are relatively inexpensive compared to prices in the 1970s. This rule aims to reduce development costs of projects.
Rule of Generation
Developers should avoid writing code by hand and instead write abstract high-level programs that generate code. This rule aims to reduce human errors and save time.
Rule of Optimization
Developers should prototype software before polishing it. This rule aims to prevent developers from spending too much time for marginal gains.
Rule of Diversity
Developers should design their programs to be flexible and open. This rule aims to make programs flexible, allowing them to be used in ways other than those their developers intended.
Rule of Extensibility
Developers should design for the future by making their protocols extensible, allowing for easy plugins without modification to the program's architecture by other developers, noting the version of the program, and more. This rule aims to extend the lifespan and enhance the utility of the code the developer writes.

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 in 9 paramount precepts:

  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 data in flat text 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.

"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 which simplicity of both the interface and the implementation are more important than any other attributes 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 used 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", or 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 such as read(), write(), open(), and select(). 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 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 key presses—small wrappers could be added to system calls so as to retry the call right away if this EINTR error was raised. Thus, the problem was solved in a simple manner.

  1. "The Pragmatic Programmer: From Journeyman to Master". 
  2. McIlroy, M. D. (1987). A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971–1986 (PDF) (Технічний звіт). CSTR. № 139. Bell Labs.
  3. Norman, Don (1981).
  4. "JOSPEH H. CONDON".
  5. а б Kernighan, Brian W. Pike, Rob.
  6. а б Rob Pike, Brian W. Kernighan (October 1984).
  7. http://cm.bell-labs.com/cm/cs/who/dmr/mdmpipe.html
  8. Basics of the Unix Philosophy
  9. Eric S. Raymond.
  10. Douglas McIlroy.
  11. Bill McGonigle.
  12. Varghese, Sam.
  13. "Interview with Patrick Volkerding of Slackware". linuxquestions.org. 2012-06-07.
  14. Raymond, Eric (2003-09-19).
  15. Raymond, Eric (2003-09-19).
  16. Raymond, Eric.
  17. Raymond, Eric (19 September 2003).

References

[ред. | ред. код]
[ред. | ред. код]