comma operator: keep away?

JJS crewman at bucsb.UUCP
Wed Apr 26 05:05:21 AEST 1989


In article <1989Apr24.172219.817 at utzoo.uucp> (Henry Spencer) writes:
>
>On the other hand, a C programmer who [uses a comma operator to sequence
>two closely related expression evaluations, instead of two statements]
>should ... be investigating alternate career paths, because he's clearly
>an amateur in a business that needs professionals.  Anyone who says "any
>competent programmer ought to be able to understand that!" rather than
>"I should make my code as clear as possible!" is an amateur, and one with
>an ego problem at that.  Readability is very much a matter of what you're
>used to.  Like it or lump it, most C programmers are used to [the compound
>statement] and not [the comma construct].
>

I believe that should read, 'most *Pascal* programmers are used to the compound
statement and not the comma construct'.  This is just my opinion, and one
with which many people differ, but why are C programmers always advised not
to use the unique features of C?  So far, I've been advised against:

	-- using the comma construct
	-- using the (a ? b : c) expression
	-- using an assignment as a function
	-- using "if (a)" instead of "if (a != 0)"
	-- using += -= *= /= |= &= ^=
	-- using << >> <<= >>=
	-- using complex pointer-integer expressions
	-- generally complex expressions: map |= (line[k++] = string[j++]);
	-- writing compact source code
	etc.

I've also been advised to go out of my way to make my C programs look like
programs written in another language:

#define begin 	{
#define end	}
#define then			/* if (a == 1) then return; */
#define when	break; case	/* when 'a': foo(); when 'b': bar() */
#define otherwise break; default: /* otherwise baz(); */
etc.

Getting back to the poster of the above article, why is the person who likes
the comma construct an amateur?  Is it because s/he likes a unique feature
of C?  Or is it really because the above "professional" would get confused
reading such code?  In a business which so sorely "needs professionals", why
are we bending over backwards to make our programs easier to read for ama-
teurs?

C is designed to be a low-level language.  It's advantage over machine
language and even higher-level languages is its power derived from its
simplicity and compactness.  It is in this way an elegant language; as
C programmers, we have the tools to make powerful programs compact.  Yet
we are constantly advised to throw away these tools.  I believe that
that is VERY unprofessional.

I repeat: this is just my opinion so mail flames to me.

                  -- JJS



More information about the Comp.unix.questions mailing list