It has happened again: A simple command that was written to perform a specific task has evolved into a re-usable command that becomes part of a programmer's toolbox.
Many commands evolve as follows.
The initial version of the command contains hard-coded data values and only one path of execution. Upon reflection it is decided that by parameterizing the command (i.e. make the hard-coded values into variables that are initialized using command-line arguments), the command can be re-used in other contexts. Upon further reflection, it is realized that the command can become re-usable if we allow its default behavior to be altered. This can be accomplished by adding a command-line option. Initially, we think that only one alternate behavior is necessary, but more reflection results in the addition of numerous options to cause the command to execute in a variety of ways.
Here is an example.
A message is posted to the PLUG-discussion list about needing to search a collection of files for a particular pattern. We quickly write a shell script command to do this. This version of the command supports no options, nor does it take any arguments; in other words, the beginning search location is the current working directory and the search pattern is hard-coded in the command.
Initial reflection results in a slightly more flexible version of the command. The command now supports one option and requires one argument. By default is searches from the currently working directory, but an option can be used to have the command use a different directory as its starting point. The search pattern is specified as a required command-line argument.
Further reflection allows the shell script to evolve into a re-usable command. It now supports multiple options. The beginning search directory can be specified using an option, non-recursive searching is the default with an option used to do a recursive search, and an option can be specified to do a case-insensitive search.
With each newer version of the command, the source code contains more comments and more logic for handling errors.
In order to support a more complicated command-line, the command switches to using getopts.
In many cases, the command is made available to other users by being installed in a
/usr/local/bintype directory. If this event occurs, then the source code is added to a source code control system and a manpage is authored.Time and time again a simple command evolves into a tool that becomes part of programmer's toolbox of commands.
Author: G.D.Thurman
[gdt@deru.com]
Created: 06 Nov 2002