Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!mailrus!purdue!bu-cs!buengc!bph From: bph@buengc.BU.EDU (Blair P. Houghton) Newsgroups: comp.lang.c Subject: Re: A brace vs. indentation hypothesis (was Re: Braces are not Compiler-Fluff.) Message-ID: <1913@buengc.BU.EDU> Date: 17 Jan 89 15:58:50 GMT References: <272@twwells.uucp> <849@unh.UUCP> <9379@ihlpb.ATT.COM> <2695@ficc.uu.net> <1880@buengc.BU.EDU> <1989Jan16.120659.18777@ateng.ateng.com> Reply-To: bph@buengc.bu.edu (Blair P. Houghton) Followup-To: comp.lang.c Organization: Boston Univ. Col. of Eng. Lines: 71 In article <1989Jan16.120659.18777@ateng.ateng.com> chip@ateng.ateng.com (Chip Salzenberg) writes: >According to bph@buengc.BU.EDU (Blair P. Houghton): >> "Hint: keep those braces as close >> to their related syntactic element >> as possible,[...] > > if (condition && test) { > action(); > } > >puts about 2 inches between "if" and "{", whereas this: > > if (condition) > { > } > >makes the "if" and "{" adjacent. But in making your little improvement in the elastic strain to your eye muscles, you've forgotten to accomplish the "action()"... (cheap ;-) ) It also makes your unqualified "{}" blocks hard to see. Try this: if (condition && much longer conditional expression sequence than is really excusable, with strange arrangement ef- fects) action(); { volatile gas; fprintf(stdmess,"Don't light that match!"); explode(gas); } It's not as pathological as it might seem. If you typically place your leftbrackets on the same line as the last if-statement-right- parenthesis, then this atypical example screams "lonely subblock", and such things are rare and strange enough that they should get all the help they can in being instantly and unambiguously identified. The other one is: for (boo = foo; boo < eleventeen(foo); boo +=azillion); { extern struct votalile skunkwort; static clinging socks; /* clinging is typedeffed */ int metimbers; exhortation gurgling; /* so is exhortation */ launder(socks); gag("ick!",skunkwort); shiver(metimbers); die(gurgling); } >I see two dimensions when I look at a program. Apparently, not everyone >does. In particular, your compiler doesn't. The syntax at that right-parenthesis is the important bit, and focussing on the space immediately under the "for" or "if" definitely distracts from the important bit. --Blair "I usually see as many dimensions as I have variables..."