.TL .sp Unix: explained .AU .ft R .sp 1.2i .ps 11 markus schnalke .LP .ig .S "Goals of this talk .I Introduce the Unix philosophy .I Show that most modern software is crap .I Explain why the Unix philosophy leads to good/better software .I Convince you that good software is of matter .sp 2 .I Make you think .S Roadmap .I What is Unix? .I Background and history .I The Unix philosophy .I Real world examples .I Final thoughts .. .P "What is Unix? .S "Unix .I Operating system .LP .ti +1i Kernel (Systemcalls) .LP .ti +1i Userland .LP .ti +1i Filesystem .sp .5 .I Philosophy .P "Background and History .S "Historical background .LP The late 60s and early 70s .LP Operating systems are complex .LP Brooks's ``The Mythical Man-Month'' .LP A lot of incompatible hardware .LP Limited computing power .LP Textual input and output (line printers) .S "Timeline .LP 1968: .I MULTICS fails .LP 1969: .I Thompson, Ritchie, McIlroy, Ossanna still think about operating systems .I The pushing idea is a file system (mainly Thompson) .I The PDP-7 .LP 1970: .I Kernighan suggests the name UNIX .I Deal: a PDP-11 for a document preparation system .S "Timeline .LP 1971: .I 1st Edition .LP 1972: .I C .LP 1973: .I Rewrite of Unix in C .LP 1974: .I First publication .S "First paper 1974: Abstract .nr PS -2 .LP UNIX is a general-purpose, multi-user, interactive operating system for the Digital Equipment Corporation PDP-11/40 and 11/45 computers. It offers a number of features seldom found even in larger operating systems, including: .LP (1) a hierarchical file system incorporating demountable volumes; .LP (2) compatible file, device, and inter-process I/O; .LP (3) the ability to initiate asynchronous processes; .LP (4) system command language selectable on a per-user basis; .LP and (5) over 100 subsystems including a dozen languages. .LP This paper discusses the nature and implementation of the file system and of the user command interface. .LP \s-4CACM July 1974, vol. 17, n. 7\s0 .nr PS +2 .S "Timeline .LP 1975: .I Release of 6th Edition .LP 1976/1977: .I Lions's Book .I BSD .LP 1979: .I Release of 7th Editon .LP 1982/1983: .I System III, System V .P "Operating System .S "Kernel .I Very simple system call interface .I Very simple process creation concept .I Compatible file, device, inter-process I/O .sp .I Described in detail in the Lions's Book .S "Userland .I Tools .I Pipes and filters .I Users are programmers .I No special-treatment of the shell .sp .LP Command invocations in 1974: .sp .5 .nf 15%:\h'2c' ed 10%:\h'2c' ls \06% (each): rm, cc, cat, \fIuser-commands\fP \03% (each): who, mv, stat \02% (each): ?roff, if, db, sh, pr \01% (each): ps, as, echo, cp, pr, date, ... .sp cd ? ;-) .fi .S "ed .PS ED: box "ed" arrow right box "sed" arrow up right from ED.ne box "grep" move box dashed "gres" arrow down right from ED.se box "ex" line box "vi" .PE .S "Filesystem .LP In the 1974 paper: ``The most important role of UNIX is to provide a file system.'' .sp .I Hierarchical .I Demountable volumes .I Regular files, directories, special files .I Inodes .P "Philosophy .S "What is the Unix philosophy? .LP ``The Unix philosophy is a set of cultural norms and philosophical approaches to developing software based on the experience of leading developers of the Unix operating system.'' (wikipedia) .sp 2 .LP How the inventors of Unix write software .LP Common things in classic Unix tools .sp 2 .LP Difficult to define .S "Explanations .I Doug McIlroy (1978) .I Mike Gancarz: ``The Unix Philosophy'' (1994) .I Eric S. Raymond: ``The Art of Unix Programming'' (2003) .sp 2 .I Richard Gabriel: ``Worse is Better'' (1989) .S "Doug McIlroy .LP This is the Unix philosophy: .I Write programs that do one thing and do it well. .I Write programs to work together. .I Write programs to handle text streams, because that is a universal interface. .S "Mike Gancarz: ``The Unix Philosophy'' .I Small is beautiful. .I Make each program do one thing well. .I Build a prototype as soon as possible. .I Choose portability over efficiency. .I Store data in flat text files. .I Use software leverage to your advantage. .I Use shell scripts to increase leverage and portability. .I Avoid captive user interfaces. .I Make every program a filter. .sp 1 .LP Plus ten lesser tenets .S "Small is beautiful .LP Small software is easier to understand, write, maintain .LP Less lines of code contain less bugs .LP Monsters are large .S "Make each program do one thing well .LP Programs with many functions are large .LP One thing is easier to understand .LP Often straight forward to implement .LP Toolchests .LP Reusable .S "Build a prototype as soon as possible .LP Shows the quality of the design .LP Shows the problems of the software .LP The best way to shape a software .LP Users find bugs .LP Incremental development .S "Choose portability over efficiency .LP (Originates in a lot of incompatible hardware in history) .LP Use is most important .LP Availability .LP Only needs to be fast enough .S "Store data in flat text files .LP (originally: ``Store numerical data in flat ASCII files'') .LP Binary data is machine-dependent .LP Human readable data is: .I As generic as possible .I Is very likely supported .I Many tools work on it (Unix toolchest) .I Directly editable by humans .LP Processing needs only to be fast enough .S "Use software leverage to your advantage .LP What do we have computers for? .LP Make best use of computing power .LP Reduce development effort .LP Toolchests and a powerful shell .S "Use shell scripts to increase leverage and portability .LP Was very important in history .LP High level languages .LP Prototyping .LP Quick hacks .LP Users are ``programmers'' .S "Avoid captive user interfaces .LP Don't assume the user to be human .LP Allow non-interactive use .LP Automate .LP How does it scale? .LP Bloat .S "Make every program a filter .LP Programs transform data .LP Combine programs .LP Have one common interface .LP Toolchests .P "Case studies .S "Case studies .I .CW ls .I .CW "cat -v .I readline .I .CW "grep -R .I .CW "find -printf .I .CW sloccount .I .CW parted .I uzbl, surf, dwb, ... .I MH, nmh, mmh .ig .S "parted (UIs) .LP .ft CW .ps -7 .vs -7 .nf $ for i in libparted0debian1 parted gparted ; do > echo > echo $i > apt-cache show $i | egrep 'Size|Depends' | sort | fmt -s > done \& libparted0debian1 Depends: libblkid1 (>= 2.17.2), libc6 (>= 2.3), libdevmapper1.02.1 (>= 2:1.02.36), libuuid1 (>= 2.16) Installed-Size: 680 Size: 341462 \& parted Depends: libblkid1 (>= 2.16), libc6 (>= 2.3), libdevmapper1.02.1 (>= 2:1.02.20), libncurses5 (>= 5.7+20100313), libparted0debian1 (>= 2.2-1), libreadline6 (>= 6.0), libuuid1 (>= 2.16) Installed-Size: 288 Size: 156472 \& gparted Depends: libc6 (>= 2.3.4), libgcc1 (>= 1:4.1.1), libglib2.0-0 (>= 2.12.0), libglibmm-2.4-1c2a (>= 2.24.0), libgtk2.0-0 (>= 2.14.0), libgtkmm-2.4-1c2a (>= 1:2.20.0), libpangomm-1.4-1 (>= 2.26.0), libparted0debian1 (>= 2.2-1), libsigc++-2.0-0c2a (>= 2.0.2), libstdc++6 (>= 4.4.0) Installed-Size: 4548 Size: 1275926 .fi .S "parted (sloc) .LP .ft CW .ps -7 .vs -7 .nf $ sloccount parted-2.3/ | sed -n '/^0/q; /^SLOC/,$p' SLOC Directory SLOC-by-Language (Sorted) 35862 libparted ansic=35807,asm=36,sh=19 12002 build-aux sh=12002 7404 lib ansic=6912,sh=492 4291 parted ansic=4291 2908 tests sh=2769,ansic=139 1558 debug sh=1288,ansic=270 1183 include ansic=1183 156 partprobe ansic=156 23 scripts sh=23 16 po sed=16 \& \& $ sloccount gparted-0.7.0/ | sed -n '/^0/q; /^SLOC/,$p' SLOC Directory SLOC-by-Language (Sorted) 12774 help xml=12774 10260 src_top_dir cpp=10260 9237 top_dir sh=9237 1964 include cpp=1954,ansic=10 325 compose cpp=325 5 debian sh=5 .fi .S "MH-linke MUAs .LP MH, nmh, mmh .LP Toolchests .LP Work with mail messages like you work with files .S "Early versions of uzbl .I What is the one task a web browser covers? .I Makes very visible use of software leverage .I Suffers hard from our broken web .sp .LP surf, dwb, ... .. .P "Final thoughts .S "Final thoughts .I What is the value and cost of a feature? .I What is the value and cost of a thousand features? .I What is the value and cost of bad features? .sp .I How do we measure complexity? .I How do we strive for elegance? .sp .I What can we learn from Unix? .P "References .S Literature .I Kernighan and Pike: ``The Unix Programming Environment'' 1984. .I Doug McIlroy: ``The Unix and the Echo'' in The UNIX Programming Environment, p. 78-79. .I Pike and Kernighan: ``Program design in the UNIX environment'' (aka. ``cat -v Considered Harmful''), 1983. .CW \s-2http://harmful.cat-v.org/cat-v/\s+2 .I Kernighan and Pike: ``The Practice of Programming'', 1999. .I Mike Gancarz: ``The Unix Philosophy'', 1994. .I Eric R. Raymond: ``The Art of Unix Programming'', 2003. .I P.J. Plauger: ``Signal and Noise in Programming Languages'', Proc. of ACM'75, p. 216. .bp .I Ritchie and Thompson: ``The UNIX Time-Sharing System'', CACM, 1974, vol. 17, no. 7, p. 365-375. .I John Lions: ``Commentary on the Six Edition UNIX Operating System'', 1977. .I Steven R. Bourne: ``The UNIX System'', 1983. .I (Maurice J. Bach: ``The Design of the UNIX Operating System'', 1986.) .sp .I Fred Brooks: ``The Mythical Man-Month'' (1975) and ``No Silver Bullet'' (1986). .S .LP This talk was prepared using tools of the Heirloom project: .CW \s-2http://heirloom.sf.net\s+2 .LP The slides macros are based on .br .CW \s-2http://repo.cat-v.org/troff-slider/\s+2 .sp .LP The slides are available on my website .CW \s-2http://marmaro.de/docs/\s+2 .sp .LP .sp 2 2013-01-20 at upLUG