docs/unix-phil

view unix-phil.ms @ 8:924b2ac2d477

new text about toolchest and shell (ch03)
author meillo@marmaro.de
date Fri, 19 Feb 2010 12:31:56 +0100
parents 606f0ffca834
children 529168f49f29
line source
1 .\".if n .pl 1000i
2 .de XX
3 .pl 1v
4 ..
5 .em XX
6 .\".nr PI 0
7 .\".if t .nr PD .5v
8 .\".if n .nr PD 1v
9 .nr lu 0
10 .de CW
11 .nr PQ \\n(.f
12 .if t .ft CW
13 .ie \\$1 .if n .ul 999
14 .el .if n .ul 1
15 .if t .if !\\$1 \&\\$1\f\\n(PQ\\$2
16 .if n .if \\n(.$=1 \&\\$1
17 .if n .if \\n(.$>1 \&\\$1\c
18 .if n .if \\n(.$>1 \&\\$2
19 ..
20 .ds [. \ [
21 .ds .] ]
22 .\"----------------------------------------
23 .TL
24 Why the Unix Philosophy still matters
25 .AU
26 markus schnalke <meillo@marmaro.de>
27 .AB
28 .ti \n(.iu
29 This paper discusses the importance of the Unix Philosophy in software design.
30 Today, few software designers are aware of these concepts,
31 and thus most modern software is limited and does not make use of software leverage.
32 Knowing and following the tenets of the Unix Philosophy makes software more valuable.
33 .AE
35 .if t .2C
37 .FS
38 .ps -1
39 This paper was prepared for the seminar ``Software Analysis'' at University Ulm.
40 Mentor was professor Schweiggert. 2010-02-05
41 .br
42 You may get this document from my website
43 .CW \s-1http://marmaro.de/docs
44 .FE
46 .NH 1
47 Introduction
48 .LP
49 Building a software is a process from an idea of the purpose of the software
50 to its release.
51 No matter \fIhow\fP the process is run, two things are common:
52 the initial idea and the release.
53 The process inbetween can be of any shape.
54 The the maintainance work after the release is ignored for the moment.
55 .PP
56 The process of building splits mainly in two parts:
57 the planning of what and how to build, and implementing the plan by writing code.
58 This paper focuses on the planning part \(en the designing of the software.
59 .PP
60 Software design is the plan of how the internals and externals of the software should look like,
61 based on the requirements.
62 This paper discusses the recommendations of the Unix Philosphy about software design.
63 .PP
64 The here discussed ideas can get applied by any development process.
65 The Unix Philosphy does recommend how the software development process should look like,
66 but this shall not be of matter here.
67 Similar, the question of how to write the code is out of focus.
68 .PP
69 The name ``Unix Philosophy'' was already mentioned several times, but it was not explained yet.
70 The Unix Philosophy is the essence of how the Unix operating system and its toolchest was designed.
71 It is no limited set of rules, but what people see to be common to typical Unix software.
72 Several people stated their view on the Unix Philosophy.
73 Best known are:
74 .IP \(bu
75 Doug McIlroy's summary: ``Write programs that do one thing and do it well.''
76 .[
77 %A M. D. McIlroy
78 %A E. N. Pinson
79 %A B. A. Taque
80 %T UNIX Time-Sharing System Forward
81 %J The Bell System Technical Journal
82 %D 1978
83 %V 57
84 %N 6
85 %P 1902
86 .]
87 .IP \(bu
88 Mike Gancarz' book ``The UNIX Philosophy''.
89 .[
90 %A Mike Gancarz
91 %T The UNIX Philosophy
92 %D 1995
93 %I Digital Press
94 .]
95 .IP \(bu
96 Eric S. Raymond's book ``The Art of UNIX Programming''.
97 .[
98 %A Eric S. Raymond
99 %T The Art of UNIX Programming
100 %D 2003
101 %I Addison-Wesley
102 %O .CW \s-1http://www.faqs.org/docs/artu/
103 .]
104 .LP
105 These different views on the Unix Philosophy have much in common.
106 Especially, the main concepts are similar for all of them.
107 But there are also points on which they differ.
108 This only underlines what the Unix Philosophy is:
109 A retrospective view on the main concepts of Unix software;
110 especially those that were sucessful and unique to Unix.
111 .\" really?
112 .PP
113 Before we will have a look at concrete concepts,
114 we discuss why software design is important
115 and what problems bad design introduces.
118 .NH 1
119 Importance of software design in general
120 .LP
121 Why should we design software at all?
122 It is general knowledge, that even a bad plan is better than no plan.
123 Ignoring software design is programming without a plan.
124 This will lead pretty sure to horrible results.
125 .PP
126 The design of a software is its internal and external shape.
127 The design talked about here has nothing to do with visual appearance.
128 If we see a program as a car, then its color is of no matter.
129 Its design would be the car's size, its shape, the number and position of doors,
130 the ratio of passenger and cargo transport, and so forth.
131 .PP
132 A software's design is about quality properties.
133 Each of the cars may be able to drive from A to B,
134 but it depends on its properties whether it is a good car for passenger transport or not.
135 It also depends on its properties if it is a good choice for a rough mountain area.
136 .PP
137 Requirements to a software are twofold: functional and non-functional.
138 Functional requirements are easier to define and to verify.
139 They are directly the software's functions.
140 Functional requirements are the reason why software gets written.
141 Someone has a problem and needs a tool to solve it.
142 Being able to solve the problem is the main functional requirement.
143 It is the driving force behind all programming effort.
144 .PP
145 On the other hand, there are also non-functional requirements.
146 They are called \fIquality\fP requirements, too.
147 The quality of a software is about properties that are not directly related to
148 the software's basic functions.
149 Quality aspects are about the properties that are overlooked at first sight.
150 .PP
151 Quality is of few matter when the software gets initially built,
152 but it will be of matter in usage and maintainance of the software.
153 A short-sighted might see in developing a software mainly building something up.
154 Reality shows, that building the software the first time is only a small amount
155 of the overall work.
156 Bug fixing, extending, rebuiling of parts \(en short: maintainance work \(en
157 does soon take over the major part of the time spent on a software.
158 Not to forget the usage of the software.
159 These processes are highly influenced by the software's quality.
160 Thus, quality should never be neglected.
161 The problem is that you hardly ``stumble over'' bad quality during the first build,
162 but this is the time when you should care about good quality most.
163 .PP
164 Software design is not about the basic function of a software;
165 this requirement will get satisfied anyway, as it is the main driving force behind the development.
166 Software design is about quality aspects of the software.
167 Good design will lead to good quality, bad design to bad quality.
168 The primary functions of the software will be affected modestly by bad quality,
169 but good quality can provide a lot of additional gain from the software,
170 even at places where one never expected it.
171 .PP
172 The ISO/IEC 9126-1 standard, part 1,
173 .[
174 %I International Organization for Standarization
175 %T ISO Standard 9126: Software Engineering \(en Product Quality, part 1
176 %C Geneve
177 %D 2001
178 .]
179 defines the quality model as consisting out of:
180 .IP \(bu
181 .I Functionality
182 (suitability, accuracy, inter\%operability, security)
183 .IP \(bu
184 .I Reliability
185 (maturity, fault tolerance, recoverability)
186 .IP \(bu
187 .I Usability
188 (understandability, learnability, operability, attractiveness)
189 .IP \(bu
190 .I Efficiency
191 (time behaviour, resource utilisation)
192 .IP \(bu
193 .I Maintainability
194 (analysability, changeability, stability, testability)
195 .IP \(bu
196 .I Portability
197 (adaptability, installability, co-existence, replaceability)
198 .LP
199 These goals are parts of a software's design.
200 Good design can give these properties to a software,
201 bad designed software will miss them.
202 .PP
203 One further goal of software design is consistency.
204 Consistency eases understanding, working on, and using things.
205 Consistent internals and consistent interfaces to the outside can be provided by good design.
206 .PP
207 We should design software because good design avoids many problems during a software's lifetime.
208 And we should design software because good design can offer much gain,
209 that can be unrelated to the software main intend.
210 Indeed, we should spend much effort into good design to make the software more valuable.
211 The Unix Philosophy shows how to design software well.
212 It offers guidelines to achieve good quality and high gain for the effort spent.
215 .NH 1
216 The Unix Philosophy
217 .LP
218 The origins of the Unix Philosophy were already introduced.
219 This chapter explains the philosophy, oriented on Gancarz,
220 and shows concrete examples of its application.
222 .SH
223 Examples
224 .LP
225 Following are some examples to demonstrate how applied Unix Philosophy feels like.
226 Knowledge of using the Unix shell is assumed.
227 .PP
228 Counting the number of files in the current directory:
229 .DS
230 .CW
231 ls | wc -l
232 .DE
233 The
234 .CW ls
235 command lists all files in the current directory, one per line,
236 and
237 .CW "wc -l
238 counts the number of lines.
239 .PP
240 Counting the number of files that do not contain ``foo'' in their name:
241 .DS
242 .CW
243 ls | grep -v foo | wc -l
244 .DE
245 Here, the list of files is filtered by
246 .CW grep
247 to remove all that contain ``foo''.
248 The rest is the same as in the previous example.
249 .PP
250 Finding the five largest entries in the current directory.
251 .DS
252 .CW
253 du -s * | sort -nr | sed 5q
254 .DE
255 .CW "du -s *
256 returns the recursively summed sizes of all files
257 \(en no matter if they are regular files or directories.
258 .CW "sort -nr
259 sorts the list numerically in reverse order.
260 Finally,
261 .CW "sed 5q
262 quits after it has printed the fifth line.
263 .PP
264 The presented command lines are examples of what Unix people would use
265 to get the desired output.
266 There are also other ways to get the same output.
267 It's a user's decision which way to go.
269 .SH
270 Pipes
271 .LP
272 The examples show that many tasks on a Unix system
273 are accomplished by combining several small programs.
274 The connection between the single programs is denoted by the pipe operator `|'.
275 .PP
276 Pipes, and their extensive and easy use, are one of the great
277 achievements of the Unix system.
278 Pipes between programs have been possible in earlier operating systems,
279 but it has never been a so central part of the concept.
280 When, in the early seventies, Doug McIlroy introduced pipes for the
281 Unix system,
282 ``it was this concept and notation for linking several programs together
283 that transformed Unix from a basic file-sharing system to an entirely new way of computing.''
284 .[
285 %T Unix: An Oral History
286 %O .CW \s-1http://www.princeton.edu/~hos/frs122/unixhist/finalhis.htm
287 .]
288 .PP
289 Being able to specify pipelines in an easy way is,
290 however, not enough by itself.
291 It is only one half.
292 The other is the design of the programs that are used in the pipeline.
293 They have to interfaces that allows them to be used in such a way.
295 .SH
296 Interface architecture
297 .LP
298 Unix is, first of all, simple: Everything is a file.
299 Files are sequences of bytes, without any special structure.
300 Programs should be filters, which read a stream of bytes from ``standard input'' (stdin)
301 and write a stream of bytes to ``standard output'' (stdout).
302 .PP
303 If the files \fIare\fP sequences of bytes,
304 and the programs \fIare\fP filters on byte streams,
305 then there is exactly one standardized interface.
306 Thus it is possible to combine them in any desired way.
307 .PP
308 Even a handful of small programs will yield a large set of combinations,
309 and thus a large set of different functions.
310 This is leverage!
311 If the programs are orthogonal to each other \(en the best case \(en
312 then the set of different functions is greatest.
313 .PP
314 The Unix toolchest \fIis\fP a set of small programs that
315 are filters on byte streams.
316 They are, to a large extend, unrelated in their function.
317 Hence, the Unix toolchest provides a large set of functions
318 that can be accessed by combining the programs in the desired way.
320 .SH
321 The toolchest approach
322 .LP
323 A toolchest is a set of tools.
324 Instead of having one big tool for all tasks, one has many small tools,
325 each for one task.
326 Difficult tasks are solved by combining several of the small, simple tools.
327 .PP
328 It is easier and less error-prone to write small programs.
329 It is also easier and less error-prone to write a large set of small programs,
330 than to write one large program with all the functionality included.
331 If the small programs are combinable, then they offer even a larger set
332 of functions than the single large program.
333 Hence, one gets two advantages out of writing small, combinable programs.
334 .PP
335 There are two drawbacks of the toolchest approach.
336 First, one simple, standardized, unidirectional interface has to be sufficient.
337 If one feels the need for more ``logic'' than a stream of bytes,
338 then a different approach might be of need.
339 But it is also possbile, that he just can not imaging a design where
340 a stream of bytes is sufficient.
341 By becoming more familiar with the ``Unix style of thinking'',
342 developers will more often and easier find simple designs where
343 a stream of bytes is a sufficient interface.
344 .PP
345 The second drawback of a toolchest affects the users.
346 A toolchest is often more difficult to use for novices.
347 It is neccessary to become familiar with each of the tools,
348 to be able to use the right one in a given situation.
349 Additinally, one needs to combine the tools in a senseful way on its own.
350 This is like a sharp knive \(en it is a powerful tool in the hand of a master,
351 but of no good value in the hand of an unskilled.
352 .PP
353 However, learning single, small tool of the toolchest is easier than
354 learning a complex tool.
355 The user will have a basic understanding of a yet unknown tool,
356 if the several tools of the toolchest have a common style.
357 He will be able to transfer knowledge over one tool to another.
358 .PP
359 Moreover, the second drawback can be removed easily by adding wrappers
360 around the single tools.
361 Novice users do not need to learn several tools if a professional wraps
362 the single commands into a more high-level script.
363 Note that the wrapper script still calls the small tools;
364 the wrapper script is just like a skin around.
365 No complexity is added this way,
366 but new programs can get created out of existing one with very low effort.
367 .PP
368 A wrapper script for finding the five largest entries in the current directory
369 could look like this:
370 .DS
371 .CW
372 #!/bin/sh
373 du -s * | sort -nr | sed 5q
374 .DE
375 The script itself is just a text file that calls the command line
376 a professional user would type in directly.
377 Making the program flexible on the number of entries it prints,
378 is easily possible:
379 .DS
380 .CW
381 #!/bin/sh
382 num=5
383 [ $# -eq 1 ] && num="$1"
384 du -sh * | sort -nr | sed "${num}q"
385 .DE
386 This script acts like the one before, when called without an argument.
387 But one can also specify a numerical argument to define the number of lines to print.
389 .SH
390 A powerful shell
391 .LP
392 The Unix shell provides the possibility to combine small programs into
393 large ones easily.
394 But the powerful shell is great feature in other ways, too.
395 .PP
396 It encourages rapid prototyping.
397 It includes a scripting language with built in control statements.
398 The functions, however, are the normal programs, everyone can use on the system.
399 Thus, the programs are known and learning to program in the shell is easy.
400 Using normal programs as functions in the shell programming language
401 is only possible because they are small, combinable tools in a toolchest style.
402 .PP
403 The Unix shell encourages to write small scripts out of other programs,
404 because it is so easy to do.
405 This is a great step towards automation.
406 It is wonderful if the effort to automate a task equals the effort
407 it takes to do it the second time by hand.
408 If it is so, then the user will be happy to automate everything he does more than once.
409 .PP
410 Small programs that do one job well, standardized interfaces between them,
411 a mechanism to combine parts to larger parts, and an easy way to automate tasks,
412 this will inevitably produce software leverage.
413 Getting multiple times the benefit of an investment is a great offer.
419 .NH 2
420 Results
421 .LP
422 The unix phil is an answer to the sw design question
423 .LP
424 tool chains empower the uses of sw
428 .NH 1
429 Case study: nmh
431 .NH 2
432 History
433 .LP
434 MH, nmh.
435 They are old.
437 .NH 2
438 Contrasts to similar sw
439 .LP
440 vs. Thunderbird, mutt, mailx, pine
441 .LP
442 flexibility, no redundancy, use the shell
444 .NH 2
445 Gains of the design
446 .LP
448 .NH 2
449 Problems
450 .LP
454 .NH 1
455 Case study: uzbl
457 .NH 2
458 History
459 .LP
460 uzbl is young
462 .NH 2
463 Contrasts to similar sw
464 .LP
465 like with nmh
466 .LP
467 addons, plugins, modules
469 .NH 2
470 Gains of the design
471 .LP
473 .NH 2
474 Problems
475 .LP
476 broken web
480 .NH 1
481 Final thoughts
483 .NH 2
484 Quick summary
485 .LP
486 good design
487 .LP
488 unix phil
489 .LP
490 case studies
492 .NH 2
493 Why people should choose
494 .LP
495 Make the right choice!
497 .nr PI .5i
498 .rm ]<
499 .de ]<
500 .LP
501 .de FP
502 .IP \\\\$1.
503 \\..
504 .rm FS FE
505 ..
506 .SH
507 References
508 .[
509 $LIST$
510 .]
511 .wh -1p