LINFO

The Rule of Composition



The rule of composition is a term that is sometimes used to refer to that part of the Unix philosophy that states that programs should be designed to be connected with other programs. It might also be referred to as the rule of connection.

There is no single, standardized statement of the Unix philosophy, but if it had to be described with only a single word, that word would be modularity. Modularity refers to the development of a system from components (i.e., modules) that can be arranged or fitted together in a variety of ways. Adherence to this concept has resulted in what are widely regarded as the most efficient, robust and elegant of operating systems, thus accounting for their exceptional longevity and vitality1.

Command line programs (i.e., programs that operate in an all-text mode) can be connected to each other in Unix-like operating systems by pipes, which are one of the most useful of the original UNIX innovations. Pipes, which are designated in commands by the vertical bar character, send the output of one program to another program to become its input, thereby making possible highly specialized and efficient pipelines of commands whose results would be awkward, if not impossible, to achieve by any other means, except perhaps by the creation of large, and excessively complex monolithic programs.

A key to the success of the rule of composition has been the strong UNIX tradition of writing programs whose inputs and outputs both consist of plain text to the extent possible, rather than binary (i.e., non-plain text) data. Plain text is any string (i.e., finite sequence of characters) that consists entirely of printable characters (i.e., human readable characters) and, optionally, a very few specific types of control characters (e.g., characters indicating a tab or the start of a new line). This simple and consistent standard not only greatly facilitates the exchange of information among programs by making pipes possible, but it also makes inputs and outputs of individual programs easy for humans to read and understand.

Binary data formats are sometimes unavoidable, such as for images and compressed text. However, in many cases where complex binary formats have been used, it might be possible to use a plain text format, even at the expense of a little extra CPU (central processing unit) time, in order to improve connectivity among programs. Likewise, although GUIs (graphical user interfaces) can be very useful (particularly for new users), when creating programs that operate in a GUI, an attempt should be made to maximize the ability of such programs to utilize plain text inputs and outputs.

This ability of programs to be connected with each other is also related to other tenets of the Unix philosophy, including the rule of silence, which states that by default programs should only provide that information which is useful to most users and should avoid producing unnecessary or poorly worded output. Information that is rarely needed, is of interest to only a small minority of users or is obvious should be available through the use of options not only to avoid distracting users and avoid wasting their time, but also because it facilitates communication among programs via pipes.

The rule of composition could be contrasted with the rule of separation. The latter refers to separating policy from mechanism and to separating interfaces from engines.


________
1For example, UNIX was first invented more than 35 years ago, which is ancient by computer standards. Yet, two of its modern descendants, Linux and Mac OS X, are currently at the forefront of technological advance and and have the most rapidly growing market shares.






Created June 17, 2006.
Copyright © 2006 The Linux Information Project. All Rights Reserved.