docs/unix-phil

annotate unix-phil.ms @ 5:48f1f3465550

new content about interfaces and toolchests
author meillo@marmaro.de
date Sat, 13 Feb 2010 11:37:50 +0100
parents c707b0c5c849
children a6b837d822b7
rev   line source
meillo@2 1 .\".if n .pl 1000i
meillo@0 2 .de XX
meillo@0 3 .pl 1v
meillo@0 4 ..
meillo@0 5 .em XX
meillo@1 6 .\".nr PI 0
meillo@1 7 .\".if t .nr PD .5v
meillo@1 8 .\".if n .nr PD 1v
meillo@0 9 .nr lu 0
meillo@0 10 .de CW
meillo@0 11 .nr PQ \\n(.f
meillo@0 12 .if t .ft CW
meillo@0 13 .ie \\$1 .if n .ul 999
meillo@0 14 .el .if n .ul 1
meillo@0 15 .if t .if !\\$1 \&\\$1\f\\n(PQ\\$2
meillo@0 16 .if n .if \\n(.$=1 \&\\$1
meillo@0 17 .if n .if \\n(.$>1 \&\\$1\c
meillo@0 18 .if n .if \\n(.$>1 \&\\$2
meillo@0 19 ..
meillo@0 20 .ds [. \ [
meillo@0 21 .ds .] ]
meillo@1 22 .\"----------------------------------------
meillo@0 23 .TL
meillo@0 24 Why the Unix Philosophy matters
meillo@0 25 .AU
meillo@0 26 markus schnalke <meillo@marmaro.de>
meillo@0 27 .AB
meillo@1 28 .ti \n(.iu
meillo@2 29 This paper discusses the importance of the Unix Philosophy in software design.
meillo@0 30 Today, few software designers are aware of these concepts,
meillo@3 31 and thus most modern software is limited and does not make use of software leverage.
meillo@0 32 Knowing and following the tenets of the Unix Philosophy makes software more valuable.
meillo@0 33 .AE
meillo@0 34
meillo@2 35 .if t .2C
meillo@2 36
meillo@2 37 .FS
meillo@2 38 .ps -1
meillo@2 39 This paper was prepared for the seminar ``Software Analysis'' at University Ulm.
meillo@2 40 Mentor was professor Schweiggert. 2010-02-05
meillo@2 41 .br
meillo@2 42 You may get this document from my website
meillo@2 43 .CW \s-1http://marmaro.de/docs
meillo@2 44 .FE
meillo@2 45
meillo@0 46 .NH 1
meillo@0 47 Introduction
meillo@0 48 .LP
meillo@0 49 Building a software is a process from an idea of the purpose of the software
meillo@3 50 to its release.
meillo@0 51 No matter \fIhow\fP the process is run, two things are common:
meillo@0 52 the initial idea and the release.
meillo@3 53 The process inbetween can be of any shape.
meillo@3 54 The the maintainance work after the release is ignored for the moment.
meillo@1 55 .PP
meillo@0 56 The process of building splits mainly in two parts:
meillo@0 57 the planning of what and how to build, and implementing the plan by writing code.
meillo@3 58 This paper focuses on the planning part \(en the designing of the software.
meillo@3 59 .PP
meillo@3 60 Software design is the plan of how the internals and externals of the software should look like,
meillo@3 61 based on the requirements.
meillo@3 62 This paper discusses the recommendations of the Unix Philosphy about software design.
meillo@3 63 .PP
meillo@3 64 The here discussed ideas can get applied by any development process.
meillo@3 65 The Unix Philosphy does recommend how the software development process should look like,
meillo@3 66 but this shall not be of matter here.
meillo@0 67 Similar, the question of how to write the code is out of focus.
meillo@1 68 .PP
meillo@3 69 The name ``Unix Philosophy'' was already mentioned several times, but it was not explained yet.
meillo@1 70 The Unix Philosophy is the essence of how the Unix operating system and its toolchest was designed.
meillo@3 71 It is no limited set of rules, but what people see to be common to typical Unix software.
meillo@1 72 Several people stated their view on the Unix Philosophy.
meillo@1 73 Best known are:
meillo@1 74 .IP \(bu
meillo@1 75 Doug McIlroy's summary: ``Write programs that do one thing and do it well.''
meillo@1 76 .[
meillo@1 77 %A M. D. McIlroy
meillo@1 78 %A E. N. Pinson
meillo@1 79 %A B. A. Taque
meillo@1 80 %T UNIX Time-Sharing System Forward
meillo@1 81 %J The Bell System Technical Journal
meillo@1 82 %D 1978
meillo@1 83 %V 57
meillo@1 84 %N 6
meillo@1 85 %P 1902
meillo@1 86 .]
meillo@1 87 .IP \(bu
meillo@1 88 Mike Gancarz' book ``The UNIX Philosophy''.
meillo@1 89 .[
meillo@1 90 %A Mike Gancarz
meillo@1 91 %T The UNIX Philosophy
meillo@1 92 %D 1995
meillo@1 93 %I Digital Press
meillo@1 94 .]
meillo@1 95 .IP \(bu
meillo@1 96 Eric S. Raymond's book ``The Art of UNIX Programming''.
meillo@1 97 .[
meillo@1 98 %A Eric S. Raymond
meillo@1 99 %T The Art of UNIX Programming
meillo@1 100 %D 2003
meillo@1 101 %I Addison-Wesley
meillo@2 102 %O .CW \s-1http://www.faqs.org/docs/artu/
meillo@1 103 .]
meillo@0 104 .LP
meillo@1 105 These different views on the Unix Philosophy have much in common.
meillo@3 106 Especially, the main concepts are similar for all of them.
meillo@1 107 But there are also points on which they differ.
meillo@1 108 This only underlines what the Unix Philosophy is:
meillo@1 109 A retrospective view on the main concepts of Unix software;
meillo@1 110 especially those that were sucessful and unique to Unix.
meillo@1 111 .PP
meillo@1 112 Before we will have a look at concrete concepts,
meillo@1 113 we discuss why software design is important
meillo@1 114 and what problems bad design introduces.
meillo@0 115
meillo@0 116
meillo@0 117 .NH 1
meillo@0 118 Importance of software design
meillo@0 119 .LP
meillo@2 120 Why should we design software at all?
meillo@3 121 It is general knowledge, that a bad plan is better than no plan.
meillo@2 122 As stated earlier in this document, the process of building a software
meillo@2 123 means going from an idea to a release.
meillo@2 124 The development process tells how to get from the idea to the release.
meillo@3 125 Software design is the shape of the built software.
meillo@3 126 This means, that different designs of a software would be different target points to go to.
meillo@3 127 Thus, the design of a software defines the global direction the development goes.
meillo@2 128 .PP
meillo@2 129 It is not enough that the released software offers all requested functionality.
meillo@2 130 It is a misbelief that only function matters.
meillo@2 131 Building a software the first time is only a small part of the overall work.
meillo@2 132 The larger part begins when the software is released for the first time
meillo@2 133 \(en maintainance and extending work..
meillo@2 134 This part soon covers more time than the time which was needed to build the software the first time.
meillo@2 135 .\" cf. brooks?
meillo@2 136 .PP
meillo@2 137 The extendability and maitainability of a software highly depends on its design.
meillo@2 138 Good design eases these tasks much.
meillo@2 139 Bad design, in contrast, requires much more effort for maintaining and
meillo@2 140 extending the software.
meillo@2 141 Developers should, for their own best, have maintainability and extendability in mind
meillo@2 142 when they design the software.
meillo@2 143 .PP
meillo@3 144 Users of the software, in contrast, do not care about maintainability and extendability,
meillo@2 145 at least not directly.
meillo@2 146 They care about usability and flexibility.
meillo@2 147 They want the software to directly solve their problems.
meillo@2 148 They want to be able to to use all its functions if they learned a few of them.
meillo@2 149 They want to use the software for similar tasks.
meillo@2 150 Software is successful if users enjoy using it.
meillo@2 151 Good software design can offer great flexibility and usability.
meillo@2 152 .PP
meillo@2 153 Good design matters for developers \fIand\fP for users.
meillo@2 154 Hence both groups should care about good software design.
meillo@2 155 Bad design limits the software in some way.
meillo@2 156 It may still provide all requested function, but it will have worse quality,
meillo@2 157 and thus require more work effort for developers or frustrate users.
meillo@2 158 .PP
meillo@2 159 Good software design is to the implementation like data structures are to algorithms
meillo@2 160 \(en if you get the former right, then you do not need to care about the latter,
meillo@2 161 it will simply go the right way.
meillo@2 162 .\" cf. ??? ``good data, bad algos''
meillo@0 163
meillo@0 164
meillo@0 165
meillo@0 166
meillo@0 167 .NH 1
meillo@0 168 The Unix Philosophy
meillo@4 169 .LP
meillo@4 170 The origins of the Unix Philosophy were already introduced.
meillo@4 171 This chapter explains the philosophy and shows concrete examples of its application.
meillo@5 172
meillo@5 173 .SH
meillo@4 174 Examples
meillo@4 175 .LP
meillo@4 176 Following are some examples to demonstrate how applied Unix Philosophy feels like.
meillo@4 177 Knowledge of using the Unix shell is assumed.
meillo@4 178 .PP
meillo@4 179 Counting the number of files in the current directory:
meillo@4 180 .DS
meillo@4 181 .CW
meillo@4 182 ls | wc -l
meillo@4 183 .DE
meillo@4 184 The
meillo@4 185 .CW ls
meillo@4 186 command lists all files in the current directory, one per line,
meillo@4 187 and
meillo@4 188 .CW "wc -l
meillo@4 189 counts how many lines they are.
meillo@4 190 .PP
meillo@4 191 Counting all files that do not contain ``foo'' in their name:
meillo@4 192 .DS
meillo@4 193 .CW
meillo@4 194 ls | grep -v foo | wc -l
meillo@4 195 .DE
meillo@4 196 Here, the list of files is filtered by
meillo@4 197 .CW grep
meillo@4 198 to remove all that contain ``foo''.
meillo@4 199 The rest is the same as in the previous example.
meillo@4 200 .PP
meillo@4 201 Finding the five largest entries in the current directory.
meillo@4 202 .DS
meillo@4 203 .CW
meillo@4 204 du -s * | sort -nr | sed 5q
meillo@4 205 .DE
meillo@4 206 .CW "du -s *
meillo@4 207 returns the recursively summed sizes of all files
meillo@4 208 -- no matter if they are regular files or directories.
meillo@4 209 .CW "sort -nr
meillo@4 210 sorts the list numerically in reverse order.
meillo@4 211 Finally,
meillo@4 212 .CW "sed 5q
meillo@4 213 quits after it has printed the fifth line.
meillo@4 214 .PP
meillo@4 215 The presented command lines are examples of what Unix people would use
meillo@4 216 to get the desired output.
meillo@4 217 There are also other ways to get the same output.
meillo@4 218 It's a user's decision which way to go.
meillo@5 219
meillo@5 220 .SH
meillo@4 221 Pipes
meillo@4 222 .LP
meillo@4 223 The examples show that a lot of tasks on a Unix system
meillo@4 224 are accomplished by combining several small programs.
meillo@4 225 The connection between the single programs is denoted by the pipe operator `|'.
meillo@4 226 .PP
meillo@4 227 Pipes, and their extensive and easy use, are one of the great
meillo@4 228 achievements of the Unix system.
meillo@4 229 Pipes between programs have been possible in earlier operating systems,
meillo@4 230 but it has never been a so central part of the concept.
meillo@4 231 When, in the early seventies, Doug McIlroy introduced pipes for the
meillo@4 232 Unix system,
meillo@4 233 ``it was this concept and notation for linking several programs together
meillo@4 234 that transformed Unix from a basic file-sharing system to an entirely new way of computing.''
meillo@4 235 .[
meillo@4 236 %T Unix: An Oral History
meillo@5 237 %O .CW \s-1http://www.princeton.edu/~hos/frs122/unixhist/finalhis.htm
meillo@4 238 .]
meillo@4 239 .PP
meillo@4 240 Being able to specify pipelines in an easy way is,
meillo@4 241 however, not enough by itself.
meillo@5 242 It is only one half.
meillo@4 243 The other is the design of the programs that are used in the pipeline.
meillo@5 244 They have to be of an external shape that allows them to be be used in such a way.
meillo@5 245
meillo@5 246 .SH
meillo@5 247 Interface architecture
meillo@5 248 .LP
meillo@5 249 Unix is, first of all, simple: Everything is a file.
meillo@5 250 Files are sequences of bytes, without any special structure.
meillo@5 251 Programs should be filters, which read a stream of bytes from ``standard input'' (stdin)
meillo@5 252 and write a stream of bytes to ``standard output'' (stdout).
meillo@5 253 .PP
meillo@5 254 If our files \fIare\fP sequences of bytes,
meillo@5 255 and our programs \fIare\fP filters on byte streams,
meillo@5 256 then there is exactly one standardized interface.
meillo@5 257 Thus it is possible to combine them in any desired way.
meillo@5 258 .PP
meillo@5 259 Even a handful of small programs will yield a large set of combinations,
meillo@5 260 and thus a large set of different functions.
meillo@5 261 This is leverage!
meillo@5 262 .PP
meillo@5 263 If the programs are orthogonal to each other \(en the best case \(en
meillo@5 264 then the set of different functions is greatest.
meillo@5 265 .PP
meillo@5 266 Now, the Unix toolchest is a set of small programs that
meillo@5 267 are filters on byte streams.
meillo@5 268 They are to a large extend unrelated in their function.
meillo@5 269 Hence, the Unix toolchest provides a large set of functions
meillo@5 270 that can be accessed by combining the programs in the desired way.
meillo@5 271
meillo@5 272 .SH
meillo@5 273 Advantages of toolchests
meillo@5 274 .LP
meillo@5 275 A toolchest is a set of tools.
meillo@5 276 Instead of having one big tool for all tasks, one has many small tools,
meillo@5 277 each for one task.
meillo@5 278 Difficult tasks are solved by combining several of the small, simple tools.
meillo@5 279 .PP
meillo@5 280 It is easier and less error-prone to write small programs.
meillo@5 281 It is also easier and less error-prone to write a large set of small programs,
meillo@5 282 than to write one large program with all the functionality included.
meillo@5 283 If the small programs are combinable, then they offer even a larger set
meillo@5 284 of functions than the single large program.
meillo@5 285 Hence, one gets two advantages out of writing small, combinable programs.
meillo@5 286 .PP
meillo@5 287 There are two drawbacks of the toolchest approach.
meillo@5 288 First, one simple, standardized, unidirectional Interface has to be sufficient.
meillo@5 289 If one feels the need for more ``logic'' than a stream of bytes,
meillo@5 290 then a different approach might be of need, or, more likely,
meillo@5 291 he just did not came to a design where a stream of bytes is sufficient.
meillo@5 292 The other drawback of a toolchest affects the users.
meillo@5 293 A toolchest is often more difficult to use for novices.
meillo@5 294 It is neccessary to become familiar with each of the tools,
meillo@5 295 to be able to use the right one in a given situation.
meillo@5 296 Additinally, one needs to combine the tools in a senseful way on its own.
meillo@5 297 This is like a sharp knive \(en it is a powerful tool in the hand of a master,
meillo@5 298 but of no good value in the hand of an unskilled.
meillo@5 299 .PP
meillo@5 300 Luckily, the second drawback can be solved easily by adding wrappers around the single tools.
meillo@5 301 Novice users do not need to learn several tools if a professional wraps
meillo@5 302 the single commands into a single script.
meillo@5 303 Note that the wrapper script still calls the small tools;
meillo@5 304 the wrapper script is just like a skin around.
meillo@5 305 No complexity is added this way.
meillo@5 306 .PP
meillo@5 307 A wrapper script for finding the five largest entries in the current directory
meillo@5 308 could look like this:
meillo@5 309 .DS
meillo@5 310 .CW
meillo@5 311 #!/bin/sh
meillo@5 312 du -s * | sort -nr | sed 5q
meillo@5 313 .DE
meillo@5 314 The script itself is just a text file that calls the command line
meillo@5 315 a professional user would type in directly.
meillo@5 316
meillo@5 317
meillo@5 318
meillo@0 319
meillo@4 320
meillo@0 321
meillo@0 322 .NH 2
meillo@5 323 foo
meillo@0 324 .LP
meillo@0 325 standalone vs. tool chain
meillo@0 326 .LP
meillo@0 327 software leverage
meillo@0 328 .LP
meillo@0 329 possiblities
meillo@0 330
meillo@0 331 .NH 2
meillo@0 332 Results
meillo@0 333 .LP
meillo@0 334 The unix phil is an answer to the sw design question
meillo@0 335 .LP
meillo@0 336 tool chains empower the uses of sw
meillo@0 337
meillo@0 338 .NH 1
meillo@0 339 Case study: nmh
meillo@0 340
meillo@0 341 .NH 2
meillo@0 342 History
meillo@0 343 .LP
meillo@0 344 MH, nmh.
meillo@0 345 They are old.
meillo@0 346
meillo@0 347 .NH 2
meillo@0 348 Contrasts to similar sw
meillo@0 349 .LP
meillo@0 350 vs. Thunderbird, mutt, mailx, pine
meillo@0 351 .LP
meillo@0 352 flexibility, no redundancy, use the shell
meillo@0 353
meillo@0 354 .NH 2
meillo@0 355 Gains of the design
meillo@0 356 .LP
meillo@0 357
meillo@0 358 .NH 2
meillo@0 359 Problems
meillo@0 360 .LP
meillo@0 361
meillo@0 362 .NH 1
meillo@0 363 Case study: uzbl
meillo@0 364
meillo@0 365 .NH 2
meillo@0 366 History
meillo@0 367 .LP
meillo@0 368 uzbl is young
meillo@0 369
meillo@0 370 .NH 2
meillo@0 371 Contrasts to similar sw
meillo@0 372 .LP
meillo@0 373 like with nmh
meillo@0 374 .LP
meillo@0 375 addons, plugins, modules
meillo@0 376
meillo@0 377 .NH 2
meillo@0 378 Gains of the design
meillo@0 379 .LP
meillo@0 380
meillo@0 381 .NH 2
meillo@0 382 Problems
meillo@0 383 .LP
meillo@0 384 broken web
meillo@0 385
meillo@0 386 .NH 1
meillo@0 387 Final thoughts
meillo@0 388
meillo@0 389 .NH 2
meillo@0 390 Quick summary
meillo@0 391 .LP
meillo@0 392 good design
meillo@0 393 .LP
meillo@0 394 unix phil
meillo@0 395 .LP
meillo@0 396 case studies
meillo@0 397
meillo@0 398 .NH 2
meillo@0 399 Why people should choose
meillo@0 400 .LP
meillo@0 401 Make the right choice!
meillo@0 402
meillo@0 403 .nr PI .5i
meillo@0 404 .rm ]<
meillo@0 405 .de ]<
meillo@0 406 .LP
meillo@0 407 .de FP
meillo@0 408 .IP \\\\$1.
meillo@0 409 \\..
meillo@0 410 .rm FS FE
meillo@0 411 ..
meillo@0 412 .SH
meillo@0 413 References
meillo@0 414 .[
meillo@0 415 $LIST$
meillo@0 416 .]
meillo@0 417 .wh -1p