Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!ucbvax!hplabs!hpfcso!hplisa!hplvli!boyne From: boyne@hplvli.HP.COM (Art Boyne) Newsgroups: comp.lang.c Subject: Re: Re: C style peeve and knowing the rules Message-ID: <340019@hplvli.HP.COM> Date: 26 Mar 90 16:53:23 GMT References: <19356@megaron.cs.arizona.edu> Organization: Loveland Inst. Div Lines: 53 In article <19356@megaron.cs.arizona.edu> Robert J. Drabek wrote: >In article <340018@hplvli.HP.COM>, boyne@hplvli.HP.COM (Art Boyne) writes: >> jgk@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@hplvla.hp.com