From: nick@kralizec.zeta.org.au (Nick Andrew)
Newsgroups: news.software.b
Subject: Re: inews in C - shell/awk scripts are unreliable!
Date: 16 Oct 92 10:48:27 GMT
Organization: Kralizec Dialup Unix Sydney: +61-2-837-1183 V.32

geoff@world.std.com (Geoff Collyer) writes:

>The work on recoding parts of inews in C is done.  The Performance
>Release contains the result.

Bravo. I'm currently running B-news and holding off from C-news. The
reason is principally due to the extensive use of shell scripts and
rich use of Unix commands in the C-news front ends.

Shell scripts, especially those which make heavy use of commands like
awk and sed, are inherently less precise than corresponding C code.
When coding these scripts, certain assumptions are made which cause
problems when the input data is not as expected.

Two examples:

1. The recent fiasco about an "empty newgroup" message. A script just
ignored the fact that there was no actual group name given, because the
parsing of the string is more-or-less automatic in a shell script.

A C programmer would never make such a mistake, because the C program
has to parse the string explicitly. Furthermore, the programmer would
probably ensure that the newsgroup name only contained valid characters!

2. C-news "rnews" does not support the unbatching feature of B-news.
This caused me a lot of pain. Anyway the B-news rnews supported the
detection of #! rnews 12345 at the start of a message, to trigger
automatic unpacking of the contents into several messages.

C-News does not support this. Ok, I can live with it. But what happens
if I feed such a batch into C-news rnews? It uses an Awk script to
parse the headers. It traps each ':' header line and uses the left and
right parts to update an array of the form: hdrval["header"] = "value".
If the message does not contain a ':' in its first line, the Awk script
falls through to the reporting (or message body) clause, and then
cheerfully bombs out with the message "awk: hdrval: not an array". The
message itself is dumped into dead.article.


Furthermore, the character escaping and parsing of shell scripts is
considerably more complex (and thus error-prone) than C syntax. That
makes maintenance a nightmare. For example,

	greppat="^`echo $1 | sed 's/\./\\\\./g' ` "

is a typical line from C-news. Modify at your own risk, I say! A slipped
backslash and you're ash!

Finally, I'd like to point out that C-news shell scripts also contain
code which is unrelated to the task at hand. For example, let's look
at the first few lines from the recently-patched newgroup.sh:

: || exec /bin/sh $0 $argv:q
# uncomment the following if you have trouble with older ksh's on USG systems
#(alias) >/dev/null 2>&1 && exec /bin/sh "$0" ${1+"$@"}

It is not at all elegant.

Shell scripts and awk scripts have a place in the world, but they aren't
sufficiently robust as programming languages to control a major system
such as USENET News.

So in summary I'd like to recommend to the C-news developers to avoid
scripts wherever possible, and particularly in mission-critical code
like front-ends. I recognise your arguments about "not encoding local
policy in C" and "not time critical code". However, though it was
probably fast to write, it is also difficult to understand, difficult
to maintain, and difficult to verify for correctness. Where the code is
mission-critical, use a precise language - C.

Nick.
-- 
Kralizec Dialup Unix (Public Access)    Data: +61-2-837-1183, 14400 24hrs 8N1
Zeta Microcomputer Software             Data: +61-2-837-1868, 2400 24hrs 8N1
P.O. Box 177, Riverstone NSW 2765       Plan: To beat Gnuchess 4.1 !
Newsgroups: news.software.b