Nixers Book Club - Book #4: The Art of UNIX Programming - Community & Forums Related Discussions
Users browsing this thread: 3 Guest(s)
|
|||
Chapter 11 touches again the topic of interfaces.
The chapter compares CLI with GUI. I do not like this comparison, instead I want to compare whether the program is inherently interactive, and thus cannot be scriptable, or not. Games, editors and browsers are inherently interactive, and a GUI (or TUI/curses) interface is better than a CLI. The chapter then lists unix interface design patterns for scriptable programs. • The first pattern is the filter. The author declares that filters are non-interactive, but nowadays there are interactive filters, like fzf(1) and dmenu(1). He then enumerates the rules for filters. Cat-like filters are filters that can get input from stdin or from a list of files passed as arguments (which can include the stdin itself, if the file name is “-”). • Then there is the “cantrip” interface pattern, used for program that reads no input and produces no output, but have a side effect (like rm(1), touch(1), etc). • The source interface pattern gets data from the environment, not from its input, and generate an output. The sink interface are programs that read input and generate no output, but change the environment. Examples are lpr(1) and mail(1). The author mentions “sponge” as a program that reads all input before process it, there is also a program called sponge that takes its input and save on a file. Very useful. • Compiler interface, like the cantrip, change the environment, but it actually reads a input from a file and writes the output to a file. Examples are tar(1) and cc(1). • ed interface gets it input from the user, so they are interactive Examples are ed(1) and gdb(1). Those programs are barely scriptable. I made this small table Code: UNIX interface design patterns for scriptable programs: The roguelike interface pattern is not scriptable. Such programs rely on complex keyboard commands that appeals to touch-typists who don't like to move the hand from keyboard to mouse. Examples are nethack(1), vi(1) and emacs(1). Then the author list some interface patterns for design patterns that separate engine from interface (or mechanism from policy). Chapter 12 details the rule of optmization (Protogype before polishing. Get it working before you optmize it). The lessons in the chapter can be summarized in a Donald Knuth quote: Quote:Premature optimization is the root of all evil |
|||