C programming style
Michael J. Tuciarone
tooch at avsdS.UUCP
Thu Jul 18 04:36:15 AEST 1985
Awww, c'mon folks.
This whole discussion has become become silly enough without it
degenerating into flames concerning "professionalism" and so
forth. If you're reading this, someone is sufficiently convinced
of your qualifications that they gave you a computer account. (Or
at least you know enough not to break things.) If you can *write*
to the net, you are able to wade through Unix [tm blah blah] do-
cumentation and operate the system and programs...de facto, not a
rank amateur.
Regardless, this is not net.flame. Let's try to have a little
professional courtesy and keep it clean, ok?
And about "style" and "idiom"...Computer languages are generally
designed to either fit a particular application (e.g. C, Forth,
Ada) or demonstrate a principle (e.g., Pascal, APL, Lisp). Easy,
easy, flames off. The utility of a language is inseparable from
its features and syntax, which in turn are wholly dependent on
the underlying design concept. With respect to C, the very first
sentence in "The C Programmer's Manual" (you all *do* have a copy
of K&R, don't you?) reads, "C is a general-purpose programming
language which features economy of expression, modern control
flow and data structures, and a rich set of operators."
Increment and decrement operators, conditional expressions, and
returned values from assignment statements are not just a part of
C, they are accepted and preferred usage. One of the great vir-
tues of C is its (potential) brevity and elegance; "economy of
expression" is a design goal of the language! The conscientious
programmer, like any skilled craftsman, will eschew opaque or in-
comprehensible constructions. But idioms such as:
char buf[80], *cp = buf;
while ( (*cp++ = getchar()) != '0 )
;
are common, short, and understandable at a glance to the program-
mer. Phrases like the above are the heart of C. I moved to C from
Pascal and never looked back, if only because I could finally fit
the whole function on one screen.
There is, in any language, a certain overhead involved in learn-
ing the language and its idioms. But all living languages will
develop their own shorthand and common expressions. Good program-
mers, like users of *any* language, will note the expressions in
common use, and further those that are elegant, simple, and ex-
pressive while avoiding the unclear and confusing.
C may never approach Pascal for sheer readability, but the trade-
off made in favor of brevity and richness of expression seems
well worth the small extra effort invested in learning to speak
the language well.
Hoping you're still awake,
Mike Tuciarone
...{hplabs, ucbvax}!atd!tooch at avsdS
Audio/Video Systems Division
Ampex Corporation
"One of the [Allied-]Signal Companies"
More information about the Comp.lang.c
mailing list