meillo@2: .\".if n .pl 1000i meillo@0: .de XX meillo@0: .pl 1v meillo@0: .. meillo@0: .em XX meillo@1: .\".nr PI 0 meillo@1: .\".if t .nr PD .5v meillo@1: .\".if n .nr PD 1v meillo@0: .nr lu 0 meillo@0: .de CW meillo@0: .nr PQ \\n(.f meillo@0: .if t .ft CW meillo@0: .ie \\$1 .if n .ul 999 meillo@0: .el .if n .ul 1 meillo@0: .if t .if !\\$1 \&\\$1\f\\n(PQ\\$2 meillo@0: .if n .if \\n(.$=1 \&\\$1 meillo@0: .if n .if \\n(.$>1 \&\\$1\c meillo@0: .if n .if \\n(.$>1 \&\\$2 meillo@0: .. meillo@0: .ds [. \ [ meillo@0: .ds .] ] meillo@1: .\"---------------------------------------- meillo@0: .TL meillo@6: Why the Unix Philosophy still matters meillo@0: .AU meillo@0: markus schnalke meillo@0: .AB meillo@1: .ti \n(.iu meillo@2: This paper discusses the importance of the Unix Philosophy in software design. meillo@0: Today, few software designers are aware of these concepts, meillo@3: and thus most modern software is limited and does not make use of software leverage. meillo@0: Knowing and following the tenets of the Unix Philosophy makes software more valuable. meillo@0: .AE meillo@0: meillo@2: .if t .2C meillo@2: meillo@2: .FS meillo@2: .ps -1 meillo@2: This paper was prepared for the seminar ``Software Analysis'' at University Ulm. meillo@2: Mentor was professor Schweiggert. 2010-02-05 meillo@2: .br meillo@2: You may get this document from my website meillo@2: .CW \s-1http://marmaro.de/docs meillo@2: .FE meillo@2: meillo@0: .NH 1 meillo@0: Introduction meillo@0: .LP meillo@0: Building a software is a process from an idea of the purpose of the software meillo@3: to its release. meillo@0: No matter \fIhow\fP the process is run, two things are common: meillo@0: the initial idea and the release. meillo@3: The process inbetween can be of any shape. meillo@3: The the maintainance work after the release is ignored for the moment. meillo@1: .PP meillo@0: The process of building splits mainly in two parts: meillo@0: the planning of what and how to build, and implementing the plan by writing code. meillo@3: This paper focuses on the planning part \(en the designing of the software. meillo@3: .PP meillo@3: Software design is the plan of how the internals and externals of the software should look like, meillo@3: based on the requirements. meillo@3: This paper discusses the recommendations of the Unix Philosphy about software design. meillo@3: .PP meillo@3: The here discussed ideas can get applied by any development process. meillo@3: The Unix Philosphy does recommend how the software development process should look like, meillo@3: but this shall not be of matter here. meillo@0: Similar, the question of how to write the code is out of focus. meillo@1: .PP meillo@3: The name ``Unix Philosophy'' was already mentioned several times, but it was not explained yet. meillo@1: The Unix Philosophy is the essence of how the Unix operating system and its toolchest was designed. meillo@3: It is no limited set of rules, but what people see to be common to typical Unix software. meillo@1: Several people stated their view on the Unix Philosophy. meillo@1: Best known are: meillo@1: .IP \(bu meillo@1: Doug McIlroy's summary: ``Write programs that do one thing and do it well.'' meillo@1: .[ meillo@1: %A M. D. McIlroy meillo@1: %A E. N. Pinson meillo@1: %A B. A. Taque meillo@1: %T UNIX Time-Sharing System Forward meillo@1: %J The Bell System Technical Journal meillo@1: %D 1978 meillo@1: %V 57 meillo@1: %N 6 meillo@1: %P 1902 meillo@1: .] meillo@1: .IP \(bu meillo@1: Mike Gancarz' book ``The UNIX Philosophy''. meillo@1: .[ meillo@1: %A Mike Gancarz meillo@1: %T The UNIX Philosophy meillo@1: %D 1995 meillo@1: %I Digital Press meillo@1: .] meillo@1: .IP \(bu meillo@1: Eric S. Raymond's book ``The Art of UNIX Programming''. meillo@1: .[ meillo@1: %A Eric S. Raymond meillo@1: %T The Art of UNIX Programming meillo@1: %D 2003 meillo@1: %I Addison-Wesley meillo@2: %O .CW \s-1http://www.faqs.org/docs/artu/ meillo@1: .] meillo@0: .LP meillo@1: These different views on the Unix Philosophy have much in common. meillo@3: Especially, the main concepts are similar for all of them. meillo@1: But there are also points on which they differ. meillo@1: This only underlines what the Unix Philosophy is: meillo@1: A retrospective view on the main concepts of Unix software; meillo@1: especially those that were sucessful and unique to Unix. meillo@6: .\" really? meillo@1: .PP meillo@1: Before we will have a look at concrete concepts, meillo@1: we discuss why software design is important meillo@1: and what problems bad design introduces. meillo@0: meillo@0: meillo@0: .NH 1 meillo@6: Importance of software design in general meillo@0: .LP meillo@2: Why should we design software at all? meillo@6: It is general knowledge, that even a bad plan is better than no plan. meillo@6: Ignoring software design is programming without a plan. meillo@6: This will lead pretty sure to horrible results. meillo@2: .PP meillo@6: The design of a software is its internal and external shape. meillo@6: The design talked about here has nothing to do with visual appearance. meillo@6: If we see a program as a car, then its color is of no matter. meillo@6: Its design would be the car's size, its shape, the number and position of doors, meillo@6: the ratio of passenger and cargo transport, and so forth. meillo@2: .PP meillo@6: A software's design is about quality properties. meillo@6: Each of the cars may be able to drive from A to B, meillo@6: but it depends on its properties whether it is a good car for passenger transport or not. meillo@6: It also depends on its properties if it is a good choice for a rough mountain area. meillo@2: .PP meillo@6: Requirements to a software are twofold: functional and non-functional. meillo@6: Functional requirements are easier to define and to verify. meillo@6: They are directly the software's functions. meillo@6: Functional requirements are the reason why software gets written. meillo@6: Someone has a problem and needs a tool to solve it. meillo@6: Being able to solve the problem is the main functional requirement. meillo@6: It is the driving force behind all programming effort. meillo@2: .PP meillo@6: On the other hand, there are also non-functional requirements. meillo@6: They are called \fIquality\fP requirements, too. meillo@6: The quality of a software is about properties that are not directly related to meillo@6: the software's basic functions. meillo@6: Quality aspects are about the properties that are overlooked at first sight. meillo@2: .PP meillo@6: Quality is of few matter when the software gets initially built, meillo@6: but it will be of matter in usage and maintainance of the software. meillo@6: A short-sighted might see in developing a software mainly building something up. meillo@6: Reality shows, that building the software the first time is only a small amount meillo@6: of the overall work. meillo@6: Bug fixing, extending, rebuiling of parts \(en short: maintainance work \(en meillo@6: does soon take over the major part of the time spent on a software. meillo@6: Not to forget the usage of the software. meillo@6: These processes are highly influenced by the software's quality. meillo@6: Thus, quality should never be neglected. meillo@6: The problem is that you hardly ``stumble over'' bad quality during the first build, meillo@6: but this is the time when you should care about good quality most. meillo@6: .PP meillo@6: Software design is not about the basic function of a software; meillo@6: this requirement will get satisfied anyway, as it is the main driving force behind the development. meillo@6: Software design is about quality aspects of the software. meillo@6: Good design will lead to good quality, bad design to bad quality. meillo@6: The primary functions of the software will be affected modestly by bad quality, meillo@6: but good quality can provide a lot of additional gain from the software, meillo@6: even at places where one never expected it. meillo@6: .PP meillo@6: The ISO/IEC 9126-1 standard, part 1, meillo@6: .[ meillo@6: %I International Organization for Standarization meillo@6: %T ISO Standard 9126: Software Engineering \(en Product Quality, part 1 meillo@6: %C Geneve meillo@6: %D 2001 meillo@6: .] meillo@6: defines the quality model as consisting out of: meillo@6: .IP \(bu meillo@6: .I Functionality meillo@6: (suitability, accuracy, inter\%operability, security) meillo@6: .IP \(bu meillo@6: .I Reliability meillo@6: (maturity, fault tolerance, recoverability) meillo@6: .IP \(bu meillo@6: .I Usability meillo@6: (understandability, learnability, operability, attractiveness) meillo@6: .IP \(bu meillo@6: .I Efficiency meillo@6: (time behaviour, resource utilisation) meillo@6: .IP \(bu meillo@6: .I Maintainability meillo@6: (analysability, changeability, stability, testability) meillo@6: .IP \(bu meillo@6: .I Portability meillo@6: (adaptability, installability, co-existence, replaceability) meillo@6: .LP meillo@6: These goals are parts of a software's design. meillo@6: Good design can give these properties to a software, meillo@6: bad designed software will miss them. meillo@0: meillo@0: meillo@0: .NH 1 meillo@0: The Unix Philosophy meillo@4: .LP meillo@4: The origins of the Unix Philosophy were already introduced. meillo@4: This chapter explains the philosophy and shows concrete examples of its application. meillo@5: meillo@5: .SH meillo@4: Examples meillo@4: .LP meillo@4: Following are some examples to demonstrate how applied Unix Philosophy feels like. meillo@4: Knowledge of using the Unix shell is assumed. meillo@4: .PP meillo@4: Counting the number of files in the current directory: meillo@4: .DS meillo@4: .CW meillo@4: ls | wc -l meillo@4: .DE meillo@4: The meillo@4: .CW ls meillo@4: command lists all files in the current directory, one per line, meillo@4: and meillo@4: .CW "wc -l meillo@4: counts how many lines they are. meillo@4: .PP meillo@4: Counting all files that do not contain ``foo'' in their name: meillo@4: .DS meillo@4: .CW meillo@4: ls | grep -v foo | wc -l meillo@4: .DE meillo@4: Here, the list of files is filtered by meillo@4: .CW grep meillo@4: to remove all that contain ``foo''. meillo@4: The rest is the same as in the previous example. meillo@4: .PP meillo@4: Finding the five largest entries in the current directory. meillo@4: .DS meillo@4: .CW meillo@4: du -s * | sort -nr | sed 5q meillo@4: .DE meillo@4: .CW "du -s * meillo@4: returns the recursively summed sizes of all files meillo@4: -- no matter if they are regular files or directories. meillo@4: .CW "sort -nr meillo@4: sorts the list numerically in reverse order. meillo@4: Finally, meillo@4: .CW "sed 5q meillo@4: quits after it has printed the fifth line. meillo@4: .PP meillo@4: The presented command lines are examples of what Unix people would use meillo@4: to get the desired output. meillo@4: There are also other ways to get the same output. meillo@4: It's a user's decision which way to go. meillo@5: meillo@5: .SH meillo@4: Pipes meillo@4: .LP meillo@4: The examples show that a lot of tasks on a Unix system meillo@4: are accomplished by combining several small programs. meillo@4: The connection between the single programs is denoted by the pipe operator `|'. meillo@4: .PP meillo@4: Pipes, and their extensive and easy use, are one of the great meillo@4: achievements of the Unix system. meillo@4: Pipes between programs have been possible in earlier operating systems, meillo@4: but it has never been a so central part of the concept. meillo@4: When, in the early seventies, Doug McIlroy introduced pipes for the meillo@4: Unix system, meillo@4: ``it was this concept and notation for linking several programs together meillo@4: that transformed Unix from a basic file-sharing system to an entirely new way of computing.'' meillo@4: .[ meillo@4: %T Unix: An Oral History meillo@5: %O .CW \s-1http://www.princeton.edu/~hos/frs122/unixhist/finalhis.htm meillo@4: .] meillo@4: .PP meillo@4: Being able to specify pipelines in an easy way is, meillo@4: however, not enough by itself. meillo@5: It is only one half. meillo@4: The other is the design of the programs that are used in the pipeline. meillo@5: They have to be of an external shape that allows them to be be used in such a way. meillo@5: meillo@5: .SH meillo@5: Interface architecture meillo@5: .LP meillo@5: Unix is, first of all, simple: Everything is a file. meillo@5: Files are sequences of bytes, without any special structure. meillo@5: Programs should be filters, which read a stream of bytes from ``standard input'' (stdin) meillo@5: and write a stream of bytes to ``standard output'' (stdout). meillo@5: .PP meillo@5: If our files \fIare\fP sequences of bytes, meillo@5: and our programs \fIare\fP filters on byte streams, meillo@5: then there is exactly one standardized interface. meillo@5: Thus it is possible to combine them in any desired way. meillo@5: .PP meillo@5: Even a handful of small programs will yield a large set of combinations, meillo@5: and thus a large set of different functions. meillo@5: This is leverage! meillo@5: .PP meillo@5: If the programs are orthogonal to each other \(en the best case \(en meillo@5: then the set of different functions is greatest. meillo@5: .PP meillo@5: Now, the Unix toolchest is a set of small programs that meillo@5: are filters on byte streams. meillo@5: They are to a large extend unrelated in their function. meillo@5: Hence, the Unix toolchest provides a large set of functions meillo@5: that can be accessed by combining the programs in the desired way. meillo@5: meillo@5: .SH meillo@5: Advantages of toolchests meillo@5: .LP meillo@5: A toolchest is a set of tools. meillo@5: Instead of having one big tool for all tasks, one has many small tools, meillo@5: each for one task. meillo@5: Difficult tasks are solved by combining several of the small, simple tools. meillo@5: .PP meillo@5: It is easier and less error-prone to write small programs. meillo@5: It is also easier and less error-prone to write a large set of small programs, meillo@5: than to write one large program with all the functionality included. meillo@5: If the small programs are combinable, then they offer even a larger set meillo@5: of functions than the single large program. meillo@5: Hence, one gets two advantages out of writing small, combinable programs. meillo@5: .PP meillo@5: There are two drawbacks of the toolchest approach. meillo@5: First, one simple, standardized, unidirectional Interface has to be sufficient. meillo@5: If one feels the need for more ``logic'' than a stream of bytes, meillo@5: then a different approach might be of need, or, more likely, meillo@5: he just did not came to a design where a stream of bytes is sufficient. meillo@5: The other drawback of a toolchest affects the users. meillo@5: A toolchest is often more difficult to use for novices. meillo@5: It is neccessary to become familiar with each of the tools, meillo@5: to be able to use the right one in a given situation. meillo@5: Additinally, one needs to combine the tools in a senseful way on its own. meillo@5: This is like a sharp knive \(en it is a powerful tool in the hand of a master, meillo@5: but of no good value in the hand of an unskilled. meillo@5: .PP meillo@5: Luckily, the second drawback can be solved easily by adding wrappers around the single tools. meillo@5: Novice users do not need to learn several tools if a professional wraps meillo@5: the single commands into a single script. meillo@5: Note that the wrapper script still calls the small tools; meillo@5: the wrapper script is just like a skin around. meillo@5: No complexity is added this way. meillo@5: .PP meillo@5: A wrapper script for finding the five largest entries in the current directory meillo@5: could look like this: meillo@5: .DS meillo@5: .CW meillo@5: #!/bin/sh meillo@5: du -s * | sort -nr | sed 5q meillo@5: .DE meillo@5: The script itself is just a text file that calls the command line meillo@5: a professional user would type in directly. meillo@5: meillo@5: meillo@5: meillo@0: meillo@4: meillo@0: meillo@0: .NH 2 meillo@5: foo meillo@0: .LP meillo@0: standalone vs. tool chain meillo@0: .LP meillo@0: software leverage meillo@0: .LP meillo@0: possiblities meillo@0: meillo@0: .NH 2 meillo@0: Results meillo@0: .LP meillo@0: The unix phil is an answer to the sw design question meillo@0: .LP meillo@0: tool chains empower the uses of sw meillo@0: meillo@0: .NH 1 meillo@0: Case study: nmh meillo@0: meillo@0: .NH 2 meillo@0: History meillo@0: .LP meillo@0: MH, nmh. meillo@0: They are old. meillo@0: meillo@0: .NH 2 meillo@0: Contrasts to similar sw meillo@0: .LP meillo@0: vs. Thunderbird, mutt, mailx, pine meillo@0: .LP meillo@0: flexibility, no redundancy, use the shell meillo@0: meillo@0: .NH 2 meillo@0: Gains of the design meillo@0: .LP meillo@0: meillo@0: .NH 2 meillo@0: Problems meillo@0: .LP meillo@0: meillo@0: .NH 1 meillo@0: Case study: uzbl meillo@0: meillo@0: .NH 2 meillo@0: History meillo@0: .LP meillo@0: uzbl is young meillo@0: meillo@0: .NH 2 meillo@0: Contrasts to similar sw meillo@0: .LP meillo@0: like with nmh meillo@0: .LP meillo@0: addons, plugins, modules meillo@0: meillo@0: .NH 2 meillo@0: Gains of the design meillo@0: .LP meillo@0: meillo@0: .NH 2 meillo@0: Problems meillo@0: .LP meillo@0: broken web meillo@0: meillo@0: .NH 1 meillo@0: Final thoughts meillo@0: meillo@0: .NH 2 meillo@0: Quick summary meillo@0: .LP meillo@0: good design meillo@0: .LP meillo@0: unix phil meillo@0: .LP meillo@0: case studies meillo@0: meillo@0: .NH 2 meillo@0: Why people should choose meillo@0: .LP meillo@0: Make the right choice! meillo@0: meillo@0: .nr PI .5i meillo@0: .rm ]< meillo@0: .de ]< meillo@0: .LP meillo@0: .de FP meillo@0: .IP \\\\$1. meillo@0: \\.. meillo@0: .rm FS FE meillo@0: .. meillo@0: .SH meillo@0: References meillo@0: .[ meillo@0: $LIST$ meillo@0: .] meillo@0: .wh -1p