Unix/C program modularity
Chris Torek
chris at umcp-cs.UUCP
Fri Oct 18 10:14:58 AEST 1985
[This is in response to article <637 at dicomed.UUCP> by
papke at dicomed.UUCP (Kurt Papke).]
Perhaps I should not speak of it, since I have not been involved in
any of the actual coding, but I believe I know of a counterexample.
The Center for Automation Research (nee Computer Vision Laboratory),
umcp-cs!cvl, has a very large body of reusable code: the CVL
picture library. I do not, however, know much about this, so I
well be wrong.
But in any case, I think you have, as the saying goes, lost sight
of the forest for the trees. Why *should* Unix programmers write
reusable code for each program? Instead, or perhaps in addition
but more importantly, Unix programmers should---and at times do---
write reusable *programs*. The very `Unix Philosophy' of which
you speak is that you should create a set of tools which can be
used together to solve many problems, though each tool solves only
a subset of any one problem.
To give an example, however contrived or even erroneous---as I
mentioned, I do not work for CfAR---consider taking a set of picture
files, performing some algebraic transformation on each pixel value,
applying histogram equalization, then halftoning and printing on
an Imagen laser printer:
for i in *.pict; do
lop "your operation here" < $i | histeq | ht | pi |
qpr -q imagen-imp
done
(I have made up some of these program names; CVL people may correct
me if I have important details wrong. `lop' stands for Local
Operation on Picture, by the way.) If instead you need to display
one of these on the Grinnell:
lop "your operation here" < foo.pict | histeq | ht | put "params"
or without halftoning:
grey # Grinnel to B/W display
lop "your operation here" < foo.pict | histeq | put "params"
The point of all this is that reuse of code itself is unnecessary
if the code is in a separate program. All you need do insert the
program at the appropriate point in the pipe.
Now, if you are talking about applying the same operation to thousands
of pictures a day, then (and *only* then) you should consider taking
the `guts' of each operation out of each of the programs in question,
building argument and error handling around them, and packaging that
up as an `application'.
I have tried to keep my response within the domain of computer
graphics, as that was the focus of your article; graphics has not
been one of my studies, and I ask those who are more knowledgeable
to forgive glaring errors, or to quitely correct them (i.e., `flames
to /dev/null'). But my point---that Unix *programs* should be
reusable---applies to many domains. A proper set of tools is an
invaluable asset in any line of work.
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
UUCP: seismo!umcp-cs!chris
CSNet: chris at umcp-cs ARPA: chris at mimsy.umd.edu
More information about the Comp.lang.c
mailing list