C programming style

Alexis Dimitriadis alexis at reed.UUCP
Sun Jul 21 12:50:56 AEST 1985


> > I agree that "i++" is an abomination.  
> 
> The use of i++ when i+=1 will do is certainly an abomination!  I personally
> always use i+=1 when i just want to increment i but an not going to use
> its value in that expression.  For instance
> 
> 	for(i = 0; i < DIM; i += 1)
> 
> People ask me WHY?  As it noted above everyone just uses i++.

  I realize comments like the above are coming from people who do not
claim long experience with C, but why all the excitement?  The meaning of

	foo++;

in a statement by itself (the context in which increment operators were 
attacked) should be absolutely clear to anyone who knows what `++' does.
Years of experience with kernel code are NOT required.  `foo++;' is also
terser than `foo += 1;' (or foo = foo + 1; !!!), and it's at least as
unambiguous.  The only blemish is, it doesn't _look_ like Pascal
or FORTRAN.

  Now about things like 

	while (*++ptr);

It _does_ take effort to decipher just what they do, even if you know
the language.  _That_ is unclear, and so are things like

	if (foo = scanf("%f", &num) != 1 || num > 0) 
		fubar();
	comment(foo);

that is, complex expressions without any parentheses to indicate what
is actually happening, or (all too often), if the "professional" 
who wrote it intended it to happen.  (There is a parenthesis error in our
ctime(), for example).  This kind of thing is unclear regardless of 
familiarity with the language.

  I do not agree that only "professionals" should use C, but there
is nothing wrong with using basic features of the language in a simple way.
I think it would be nice, in fact, if more people were familiar with
"structured" languages like C and Pascal.  (I wish the teaching of BASIC
would be made into a Federal offense!)  After all, the _big_ problems with
C  readability arise from use of its facilities in an obscure 
(e.g., unstructured) way, not from the choice of operators!

Alexis Dimitriadis
exit(errno ? (perror(argv[0]), errno) : 0);
/*NOTREACHED*/
-- 
_______________________________________________
  As soon as I get a full time job, the opinions expressed above
will attach themselves to my employer, who will never be rid of
them again.

             alexis @ reed

	         ...teneron! \
...seismo!ihnp4! - tektronix! - reed.UUCP
     ...decvax! /



More information about the Comp.lang.c mailing list