C style peeve and knowing the rules
Art Boyne
boyne at hplvli.HP.COM
Tue Mar 27 02:53:23 AEST 1990
In article <19356 at megaron.cs.arizona.edu> Robert J. Drabek wrote:
>In article <340018 at hplvli.HP.COM>, boyne at hplvli.HP.COM (Art Boyne) writes:
>> jgk at osc.COM (Joe Keane) writes:
>> >Here's my biggest C style peeve. For some reason, many C programmers insist
>> >on always putting parentheses around return values, even when they're not
>>
>> Also, 'while', 'for', 'if', etc.,
>> all *require* parenthesis, so it's a reasonable habit to acquire.
>
>But as Joe Keane said, these constructs require the parenthesis for a
>particular reason and few people understand that reason.
>
>Also, Joe Keane made the point that many people put parenthesis in
>simply because they see other people do it. And there are those who
>believe return is a function and hence required!
You "conveniently" left out the centerpoint of my quote:
While 'return value;' is legal according to K&R1 (see page 203), *every*
example in my copy of the book uses 'return (value);'. Pretty obvious,
therefore, why people code that way.
Remember that for many of us in industry (vs. universities), C was learned
not from college professors, but from reading K&R1 on the job and experimenting
with the compilers available. After reading and duplicating many of the
examples in the book, the habit of using 'return (value);' was fairly well
ingrained *long* before we got to the language specification in the back of
the book. Note that K&R1 never states up front that the parentheses are
superfluous, and we have the defense that "What's good enough for Dennis
Ritchie is good enough for me".
>I require my students to use the absolute minimum number of parenthesis
>until they have ALL the rules down pat. After leaving my courses (or in
>the privacy of their own PC) they'll do whatever feels good, but I will
>have done my job as well as I can by getting them to understand these
>details.
Sorry, but this is one of the pet peeves I have with academia. Rather
than wasting your students time worrying about such trivia as few extra
parenthesis (excessive over-parenthesization, however, does indicate
a conceptual problem), as a potential future employer, I would rather
you spend more time teaching the students about algorithms, debugging
techniques, and common source-level optimizations, so that, when they do
get out into industry, they can do useful work. Particular languages are
simply fads that change with time, but the foundation of computer science
is the methods/algorithms/etc., that endure. When I was in college, the
computer science courses taught (in order) FORTRAN, CDC assembler, Algol,
and Snobol. Pascal was still a graduate-level research project, and C was
unknown. Since leaving school, I have learned both Pascal and C, as well
as 3-4 different assembly languages. A professor who would have tried
to make me learn the finer nuances of FORTRAN would have wasted my time.
Art Boyne, boyne at hplvla.hp.com
More information about the Comp.lang.c
mailing list