A brace vs. indentation hypothesis (was Re: Braces are not Compiler-Fluff.)

Blair P. Houghton bph at buengc.BU.EDU
Wed Jan 18 01:58:50 AEST 1989


In article <1989Jan16.120659.18777 at ateng.ateng.com> chip at ateng.ateng.com (Chip Salzenberg) writes:
>According to bph at 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..."



More information about the Comp.lang.c mailing list