bourne shell query
Roger Rohrbach
roger at kymijoki.wrs.com
Tue Sep 11 05:19:51 AEST 1990
goudreau at dg-rtp.dg.com (Bob Goudreau) writes:
>So let me get this straight:
>
>Making shell scripts needlessly obscure (i.e., no increase in either
>functionality or performance, and a downright *decrease* in
>readability) is supposed to be a *good thing* ??!!
>
>Call it "art" if you will, and feel free to start a rec.arts.shell
>newsgroup. I prefer to call it "bad software engineering".
I agree that shell programs should be readable, but "needlessly obscure"
is subjective. On the one hand, the shell syntax (outside of the control
structures) is pretty obscure to begin with, because it relies so much
on context-sensitive treatment of single characters. On the other hand,
the shell language per se is small enough that I don't consider certain
combinations to be obscure, even though they are not used by most casual
shell programmers; i.e., I believe it is our responsibility to learn the
language. I alway try to write in a way that minimizes obscurity intro-
duced by the former. Thus, I don't like to write complicated pipelines
that go in and out of single- and double-quotes to pass shell variables
and backquote expressions to sed scripts! But I do use goal-directed
programming (program components that "succeed" or "fail") extensively,
even though people not familiar with the style (including my boss!) call
it "obscure"- I tell them to look at Prolog or Icon, or even the C `?:'
operator (my boss only knows C :-) If a language provides a succinct
notation, I think it's good to consider the use of same "succinct", not
"obscure". As an example, I prefer
grep '^roger:' /etc/passwd > /dev/null ||
{
echo "roger is not a user" >&2
exit 1
}
to
if grep '^roger:' /etc/passwd > /dev/null
then
:
else
echo "roger is not a user" >&2
exit 1
fi
and would consider it *more* readable, especially if it were nested within
another "if-then-else" statement or loop.
Roger Rohrbach sun!wrs!roger roger at wrs.com
- Eddie sez: ----------------------------------------------- (c) 1986, 1990 -.
| {o >o |
| \ -) "I was an infinitely hot and dense dot." |
More information about the Comp.unix.shell
mailing list