C Indentation Survey Results

cottrell at NBS-VMS cottrell at NBS-VMS
Sat Apr 13 07:48:16 AEST 1985


/*
>     Many of the people also said that they would only use these comments when
>     the "}" was a long way down the program from the "{" (i.e. the next page/
>     screen or farther).

This would never happen if funxions were wholly on one page and form 
feeds were used to keep it that way. Let's get modular.
 
> I really didn't appreciate Jim Cottrell's
> reply.  No, number 1 is not any more "correct" than any of the others are
> "wrong."  The results show that there are many people that don't think
> it's the only way.

Well, looks like I'm (in)famous again...
Well, my choices were preferred by a factor of two to one. I can even 
accept putting the brace on a separate line, but the others are JUST 
PLAIN STUPID! Flexibility breeds indecision. I read a quote that said
"Dennis Ritchie is to be commended for shepherding C programmers down
a narrow path". Amen! Do it his way.

Actually, the way it SHOULD have been defined is

	IF a==b THEN
		statement
		statement
	ELSE
		statement
		statement
	END

No stupid braces, parens, or semicolons. Enuf of the `one statement'
model. This is unambiguous, clear, uses a minimum of tokens, and avoids
else's matching the wrong if. The Bourne shell is coded in this manner
with defines for the capitalized tokens. The preprocessor also has an
explicit #endif token.

> Jim also states that there must be 8 spaces in a tab.
> Who says there has to be a tab stop between each level of indentation.  I
> programmed for 4 years without using them because the machines I used
> didn't like them and my professors wanted 3 spaces.  Also, who says a tab
> stop has to be 8 spaces; typewriters have been around a lot longer than
> computer terminals, and on them you can set the stops to anything you want.

Where have you been? Tabs ARE 8 spaces. Ever since DEC (were they the 
first?) allowed tabs for formatting. I also programmed for 4 years at U Md.
indenting my code by threes only because tabs were not available. I 
wised up when I entered the real world (DECland?). A terminal is not a
typewriter. Some of them have hardcoded tabstops every eight spaces.
Your professors would have settled for four spaces or tabs if available.

In your defense, however, I note that K&R is formatted with indentations
of five spaces. This is probably due to the fact that it was typeset by
printers, who traditionally interpret tabs as five spaces, as do typists.
Also, lotsa new ttys have settable tabs, & vi has support for declaring
nonstandard tabs. Unfortunately, the tty & line printer drivers still
interpret tabs as eight spaces. EMACS formats code with indentation
levels of four spaces. This is useful for massively indented programs,
altho one could argue against massive indentation as well.

In short, tabs are eight spaces, but if we could redesign the world, I
might vote for four.

> P.S. Sorry about the assignment operator in the condition.  My goof.

Nothing wrong with assignments in conditions. It's done all the time.

To sum up, whenever there is more than one way of doing things, figure
out a reason why one way is superior. For example, some brain-damaged
cretins still insist on numbering the bits from the left end of the
word or register. This is just plain wrong. The  proof is left to the
student as an exercise. BTW, little endian is superior to big endian.
Hey, that's just the kind of guy I am. Flames expected as usual.

	jim "I'd rather be despised than ignored"	cottrell at nbs
*/



More information about the Comp.lang.c mailing list