Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!udel!sbcs!dbuksba From: dbuksba@ic.sunysb.edu (Peter B. Henderson) Newsgroups: comp.lang.c Subject: Re: C style peeve and knowing the rules Message-ID: <6894@sbcs.sunysb.edu> Date: 25 Mar 90 17:41:11 GMT References: <2205@osc.COM> <340018@hplvli.HP.COM> <19356@megaron.cs.arizona.edu> Sender: news@sbcs.sunysb.edu Organization: SUNY at Stony Brook Lines: 57 In article <19356@megaron.cs.arizona.edu> robert@cs.arizona.edu (Robert J. Drabek) writes: >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! > >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. > >Please, I know parenthesis are sometimes an aid in producing readable >code and they are also clutter which can make for less-readable code. >-- >Robert J. Drabek robert@cs.Arizona.EDU >Department of Computer Science uunet!arizona!robert >The University of Arizona 602 621 4326 >Tucson, AZ 85721 Being a student as well as a software developer, I have found it necessary to develop a standard way of coding, or a routine that I force myself to follow. I learned C by myself out of a collection of now outdated books, and have seen the return statement used in both ways. I personally use: return (2+2); The reason for this is due to the nature of C. I could create, and have, a return statement that runs off the page due to the way the return value is being acquired. I have found that by putting parenthesis around the statement I have made it mor readable for me. Being also fluent in Lisp, I understand the disadvantage of parenthesis, but nevertheless it should be used in order to maintain consistency with the programmers style. As to the students lack of understanding concerning the parenthesis, this is due to their not reading the text book, or listening to the lecture carefully, but not to their use of parenthesis. I have seen many a C text book, but never have I seen one that did not explain what difference between a function and a statement is, and that return was a statement. -Of course this is just one mans opinion. David T. Buksbaum -- +---------------------------------------------------------+ = David T. Buksbaum * *** NOTICE *** = = HAND 225A * = = Stony Brook, Ny * UNDER CONSTRUCTION =