comparison 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
comparison
equal deleted inserted replaced
4:c707b0c5c849 5:48f1f3465550
167 .NH 1 167 .NH 1
168 The Unix Philosophy 168 The Unix Philosophy
169 .LP 169 .LP
170 The origins of the Unix Philosophy were already introduced. 170 The origins of the Unix Philosophy were already introduced.
171 This chapter explains the philosophy and shows concrete examples of its application. 171 This chapter explains the philosophy and shows concrete examples of its application.
172 .NH 2 172
173 .SH
173 Examples 174 Examples
174 .LP 175 .LP
175 Following are some examples to demonstrate how applied Unix Philosophy feels like. 176 Following are some examples to demonstrate how applied Unix Philosophy feels like.
176 Knowledge of using the Unix shell is assumed. 177 Knowledge of using the Unix shell is assumed.
177 .PP 178 .PP
213 .PP 214 .PP
214 The presented command lines are examples of what Unix people would use 215 The presented command lines are examples of what Unix people would use
215 to get the desired output. 216 to get the desired output.
216 There are also other ways to get the same output. 217 There are also other ways to get the same output.
217 It's a user's decision which way to go. 218 It's a user's decision which way to go.
218 .NH 2 219
220 .SH
219 Pipes 221 Pipes
220 .LP 222 .LP
221 The examples show that a lot of tasks on a Unix system 223 The examples show that a lot of tasks on a Unix system
222 are accomplished by combining several small programs. 224 are accomplished by combining several small programs.
223 The connection between the single programs is denoted by the pipe operator `|'. 225 The connection between the single programs is denoted by the pipe operator `|'.
230 Unix system, 232 Unix system,
231 ``it was this concept and notation for linking several programs together 233 ``it was this concept and notation for linking several programs together
232 that transformed Unix from a basic file-sharing system to an entirely new way of computing.'' 234 that transformed Unix from a basic file-sharing system to an entirely new way of computing.''
233 .[ 235 .[
234 %T Unix: An Oral History 236 %T Unix: An Oral History
235 %O http://www.princeton.edu/~hos/frs122/unixhist/finalhis.htm 237 %O .CW \s-1http://www.princeton.edu/~hos/frs122/unixhist/finalhis.htm
236 .] 238 .]
237 .PP 239 .PP
238 Being able to specify pipelines in an easy way is, 240 Being able to specify pipelines in an easy way is,
239 however, not enough by itself. 241 however, not enough by itself.
240 It is only one part. 242 It is only one half.
241 The other is the design of the programs that are used in the pipeline. 243 The other is the design of the programs that are used in the pipeline.
242 They have to be of an external shape that allows them to be be used in a pipeline. 244 They have to be of an external shape that allows them to be be used in such a way.
243 245
244 246 .SH
245
246 .NH 2
247 Architecture
248 .LP
249 the most important design decision.
250
251 the topic here
252
253 .NH 2
254 Interface architecture 247 Interface architecture
248 .LP
249 Unix is, first of all, simple: Everything is a file.
250 Files are sequences of bytes, without any special structure.
251 Programs should be filters, which read a stream of bytes from ``standard input'' (stdin)
252 and write a stream of bytes to ``standard output'' (stdout).
253 .PP
254 If our files \fIare\fP sequences of bytes,
255 and our programs \fIare\fP filters on byte streams,
256 then there is exactly one standardized interface.
257 Thus it is possible to combine them in any desired way.
258 .PP
259 Even a handful of small programs will yield a large set of combinations,
260 and thus a large set of different functions.
261 This is leverage!
262 .PP
263 If the programs are orthogonal to each other \(en the best case \(en
264 then the set of different functions is greatest.
265 .PP
266 Now, the Unix toolchest is a set of small programs that
267 are filters on byte streams.
268 They are to a large extend unrelated in their function.
269 Hence, the Unix toolchest provides a large set of functions
270 that can be accessed by combining the programs in the desired way.
271
272 .SH
273 Advantages of toolchests
274 .LP
275 A toolchest is a set of tools.
276 Instead of having one big tool for all tasks, one has many small tools,
277 each for one task.
278 Difficult tasks are solved by combining several of the small, simple tools.
279 .PP
280 It is easier and less error-prone to write small programs.
281 It is also easier and less error-prone to write a large set of small programs,
282 than to write one large program with all the functionality included.
283 If the small programs are combinable, then they offer even a larger set
284 of functions than the single large program.
285 Hence, one gets two advantages out of writing small, combinable programs.
286 .PP
287 There are two drawbacks of the toolchest approach.
288 First, one simple, standardized, unidirectional Interface has to be sufficient.
289 If one feels the need for more ``logic'' than a stream of bytes,
290 then a different approach might be of need, or, more likely,
291 he just did not came to a design where a stream of bytes is sufficient.
292 The other drawback of a toolchest affects the users.
293 A toolchest is often more difficult to use for novices.
294 It is neccessary to become familiar with each of the tools,
295 to be able to use the right one in a given situation.
296 Additinally, one needs to combine the tools in a senseful way on its own.
297 This is like a sharp knive \(en it is a powerful tool in the hand of a master,
298 but of no good value in the hand of an unskilled.
299 .PP
300 Luckily, the second drawback can be solved easily by adding wrappers around the single tools.
301 Novice users do not need to learn several tools if a professional wraps
302 the single commands into a single script.
303 Note that the wrapper script still calls the small tools;
304 the wrapper script is just like a skin around.
305 No complexity is added this way.
306 .PP
307 A wrapper script for finding the five largest entries in the current directory
308 could look like this:
309 .DS
310 .CW
311 #!/bin/sh
312 du -s * | sort -nr | sed 5q
313 .DE
314 The script itself is just a text file that calls the command line
315 a professional user would type in directly.
316
317
318
319
320
321
322 .NH 2
323 foo
255 .LP 324 .LP
256 standalone vs. tool chain 325 standalone vs. tool chain
257 .LP 326 .LP
258 software leverage 327 software leverage
259 .LP 328 .LP