Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: Notesfiles $Revision: 1.7.0.8 $; site fthood Path: utzoo!watmath!clyde!cbosgd!ihnp4!inuxc!pur-ee!uiucdcs!uiucuxc!fthood!jrife From: jrife@fthood Newsgroups: net.lang.c Subject: Re: C bites / programming style [if Message-ID: <700002@fthood> Date: Wed, 28-Aug-85 08:48:00 EDT Article-I.D.: fthood.700002 Posted: Wed Aug 28 08:48:00 1985 Date-Received: Wed, 4-Sep-85 04:43:03 EDT References: <418@phri.UUCP> Lines: 57 Nf-ID: #R:phri.UUCP:-41800:fthood:700002:000:1318 Nf-From: fthood!jrife Aug 28 07:48:00 1985 > If the body is more complicated than an assignment or function >call, I put it in braces, even though they really aren't needed, thus: > > while ((foo = getfoo()) != EOF) | > { | for (x=0; x <= 10; x++) > if (foo >= bar) | { > sum += foo; | for (y=0; y <= 10; y++) > else | sumxy += x * y; > toosmall++; | } > } | > I like this programming style myself, Roy. But, one suggestion...if you move the braces over, you end up with the braces in line with the level of complication, and then *only* the opening and closing braces of a function are in the first column, thus: while ((foo = getfoo()) != EOF) { if (foo >= bar) sum += foo; else toosmall++; } It also makes constructs such as: while ((foo = getfoo()) != EOF) { if (foo >= bar) { sum += foo; bar = stuff * 3; } else { toosmall++; if (garbage != foo) garbage--; } } easy to understand. And, now, autoindent on vi works very nicely. -- ********************************* * * * Jeff Rife * * ihnp4!uiucuxc!fthood!jrife * * * * "Gene Simmons never had a * * personal computer when he * * was a kid." * * --Berke Breathed * * * *********************************