Path: utzoo!attcan!uunet!mstan!amull From: amull@Morgan.COM (Andrew P. Mullhaupt) Newsgroups: comp.lang.c Subject: Re: A question of style Summary: Uhh- you're agreeing with me, (wanna reconsider?) Message-ID: <565@s5.Morgan.COM> Date: 3 Dec 89 07:37:50 GMT References: <547@mars.Morgan.COM> <1989Nov30.001947.14883@aqdata.uucp> <427@jhereg.Minnetech.MN.ORG> Organization: Morgan Stanley & Co. NY, NY Lines: 57 In article <427@jhereg.Minnetech.MN.ORG>, mark@jhereg.Minnetech.MN.ORG (Mark H. Colburn) writes: > In article <1989Nov30.001947.14883@aqdata.uucp> sullivan@aqdata.uucp (Michael T. Sullivan) writes: > >From article <547@mars.Morgan.COM>, by amull@Morgan.COM (Andrew P. Mullhaupt): > >> > >> ...I can't think of what I would call a 'proper' use of the comma operator... - Just for the record, I said this (A.P.Mullhaupt) > > > >I posted this instead of mailing it to see what, if any, reaction it got. > >I'm always interested in coding style. > > I agree with Henry. There are few "proper" uses of a comma operator. Who's Henry? I'm not sure if you mean me or someone who agrees with me also in this thread. Worse yet, Henry might not agree with my fairly provocative statement. > The comma operator, since it is vastly underused tends to confuse most > programmer, even competent ones. I would like to elaborate: There are no good excuses for the comma operator because it masquerades as true concurrent assignment where it is a poor relation of it. The thing invites you to cram all sort of gooey side effects into for loops with increment and assignment operators. (This is the "Damn the Correctness! Full Speed Ahead" school of programming.) Now with real concurrent assignment, you really can put your loop invariant maintenance in one place: (i++ , j--) can be replaced by the much more attractive: (i, j) := (i + 1, j - 1) where concurrent assignment has the usual semantics. It evaluates the right hand side completely before making the assignments to the left hand side. Thus the swapping of two variables is simply (x, y) := (y, x) let's see that with the comma operator...maybe you like (x+=y, y=x-y, x-=y) instead? (Just kidding. The comma operator is really pretty low class compared to concurrent assignment.) One of the most important aspects of programming for clarity is to avoid the near occasion of operator precedence or side effects. You want the flow of control to be fully represented on the page in as consistent a manner as is possible. I am preparing a long treatment of this issue for posting in this newsgroup but I won't post it until it shrinks considerably, so for now I'll just divulge my provisional title: 'For construct considered harmful in C'. Later, Andrew Mullhaupt Disclaimer: Any opinions expressed above (or threatened to be expressed) are my own, as a result of careful study of the C language, and are not necessarily those of Morgan Stanley.