Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!batcomputer!cornell!uw-beaver!zephyr.ens.tek.com!gvgpsa!gold.gvg.tek.com!shaunc From: shaunc@gold.gvg.tek.com (Shaun Case) Newsgroups: comp.lang.c Subject: Re: Unnecessary parentheses (Was: Help: VAX C problem) Message-ID: <2122@gold.gvg.tek.com> Date: 2 Apr 91 22:26:28 GMT References: <4072.27f7215c@iccgcc.decnet.ab.com> <1991Apr1.203600.15721@zoo.toronto.edu> <1#.gqcm@rpi.edu> Organization: Grass Valley Group, Grass Valley, CA Lines: 48 In article <1#.gqcm@rpi.edu> xor@aix01.aix.rpi.edu (Joseph Schwartz) writes: > >Just curious...how often do you folks purposely insert unnecessary parens >into expressions? Sometimes I'll do it just to make the grouping clearer >(just in case the next person to read the code doesn't know all the >precedence rules by heart). I'm talking about expressions in general, >not just in conjunction with return or sizeof. > I probably use more "unnecessary" parens than most people -- I go to a lot of trouble to make sure my code is readable and maintainable. I figure that if the compiler is smart enough to optimize away unnecessary parentheses, why not use them if it make the code easier to follow? I often have rather large compilcated compound if statements, and the format I have found that works best for me is: if ( (test 1) || (test 2) || (test 3) || (test 4) ) { whatever(); whatever2(); etc(); } This ensures that when someone changes the code, it doesn't break immediately due to relying solely on precenence. It also allows you to put a comment off to the side for each test case. I also put parens around return values, because sometimes I change returns to exit()s, and it helps to have the parens there already, rather than waiting for the compiler to point it out. Of course, you didn't have to worry about things like this when you were writing in BASIC on your C64 with 38K of free ram, since you could fill up the entire memory space in a weekend, and be finished with your program, and never have to look at it again... those were the days! :-) // Shaun // -- Shaun Case: shaunc@gold.gvg.tek.com or atman%ecst.csuchico.edu@RELAY.CS.NET or Shaun Case of 1:119/666.0 (Fidonet) or 1@9651 (WWIVnet) --- It's enough to destroy a young moose's faith!