It is better to remain silent...

T. William Wells bill at twwells.uucp
Mon Jan 9 07:11:52 AEST 1989


It is better to remain silent and be thought a fool than to speak and
remove all doubt.

---

About half a year ago, I had a set-to on the net with Bob Webber, in
which he demonstrated an abysmal ignorance and an incredible
incompetence, not to mention an incredible arrogance.  I then added
him to my kill file (which he shares only with Weemba the Mouth) but
he managed to get my attention by posting the following gem to
alt.sources. (Ahhh... The price of archiving!)

---
/* INSERT is a program that takes two files as arguments and writes
   the contents of the first onto the second.  It can be built by
   putting this stuff in a file called INSERT.c and then typing
   make INSERT.  If this doesn't work you are on your own. */


#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/file.h>
#include <sys/param.h>

extern long lseek();

main(argc,argv)
     int argc;
     char *argv[];
{
  int fdin, fdout;
  int ReadExit;
  int ReadSize;

  char chs[MAXBSIZE];

  if (argc != 3) {
    (void)fprintf(stderr,"Error 1 [%d]: Read the source before using\n",argc);
    exit(1);
  }
  if ((fdin = open(argv[1],O_RDONLY)) == -1) {
    perror("Error 2 : Read the source before using:");
    exit(2);
  }
  if (lseek(fdin,(long) 0,L_SET) != 0) {
    perror("Error 3 : Read the source before using:");
    exit(3);
  }
  if ((fdout = open(argv[2],O_WRONLY)) == -1) {
    perror("Error 4 : Read the source before using:");
    exit(4);
  }
  if (lseek(fdout,(long) 0,L_SET) != 0) {
    perror("Error 5 : Read the source before using:");
    exit(5);
  }
  ReadSize = 0;
  while ((ReadExit = read(fdin,chs,MAXBSIZE)) >0) {
    ReadSize += ReadExit;
    if (write(fdout,chs,ReadExit) != ReadExit) {
      perror("Error 6 : Read the source before using:");
      exit(6);
    }
  }
  if (ReadExit == 0) { /* reached end of input file */
    if (ftruncate(fdout,ReadSize) != 0) {
      perror("Error 7 : Read the source before using:");
      exit(7);
    }
  } else {
    perror("Error 8 : Read the source before using:");
    exit(8);
  }
  exit(0);
}
---

(In case anyone cares, this has one patch that came over alt.sources.
The nature of the original code indicates that he didn't even run
lint over it before posting it.)

First, let's notice that this is essentially equivalent the cp
command, minus cp's frills. It does do one thing that I don't believe
all cp's do: it verifies that the copy succeeded. But one can do the
job with a little shell script that does a cp, some ls's, and some
tests.  Thus this program is an example of bad analysis: it is a new
program to do what existing tools can already do.

---

Second, it is nonportable. It is Berkeleyoid specific code.
Ftruncate marks it as such. There are also those UNIX-specific I/O
calls.

---

Third, it is a bad program, even if we didn't care about portability.

    1) The glorified numeric error codes. I mean really!  Each error
       message is just "Error so-and-so : read the source..."!  Each
       error message should have said something useful, dammit!

    2) The lack of variable naming consistency. If we're going to
       have the verbosity of words-for-names and capitalization of
       each word, names like `fdin', `fdout', and `chs' don't belong.
       (This one is arguable.)

    3) The unnecessary code sequences. The lseek's and the ftruncate
       serve no purpose that I can see.

    4) The use of a cast to create a long constant. This indicates
       ignorance of C, or a slavish obedience to a not-understood
       coding standard.

    5) Probably others, but I'm too blind mad to read it again.

---

We'll further note that writing a structured program and using a
consistent style (except for the naming and one minor glitch) did not
prevent him from writing a bad program.

---

And this !@#$%^&* guy teaches!!!!! ?????

He should be dismissed for incompetence.

---

Followups have been redirected to comp.sources.d. Mr. Webber can
save himself some effort: I've still got him in my kill file.

---
Bill
{ uunet!proxftl | novavax } !twwells!bill



More information about the Comp.lang.c mailing list