[comp.lang.c] The indentation debate

samperi@marob.MASA.COM (Dominick Samperi) (12/18/88)

In article <3261@ingr.com.> crossgl@ingr.com. (Gordon Cross) writes:
|>The "throughout eternity" comment was my reaction to the thought of someone
|>legislating my code simply because it does not conform to that someone's
|>idea of "pretty"...

Pretty? It seems to me that you should advocate a style for others to use
only if there is a logical and natural reason why that particular style is 
better than others, and not because your gut tells you that it is "pretty."
The style should facilitate the location of logical blocks of code, and should
not require the programmer to think about details that have nothing to do with
the program's logical structure. 

The purpose of using an indentation convention is to eliminate the need to
think about these trivial matters when there is more important work to be
done, and to permit other programmers who may have to work with your source
code to more easily follow the program's logical structure.

I advocate the following no-frills style:

proc()
{
	int x, y, z ; /* Easier to see ';' if it is preceded by a space. */
	...
	if(x > 0)
	{
		block1
	}
	else
	{
		block2
	}
	...
}

This style does indeed facilitate the location of blocks of code, and it
has another feature which is one of the major weapons that the programmer
has to fight complexity: consistency (if-then-blocks standout in exactly the
same way that function body blocks do).

I thought that very few people used this style, until I heard recently that
in fact several large companies recommend it. Given the logical and natural
way in which the C language was designed, I wonder if K&R might even have
used this style if it weren't so wasteful of lines on a printed page. In
large software development projects, wasting a few lines in source listings
is certainly worth the human brain cycles that it may save.

The style:

if(whatever)
  {
	block1
  }
  else
    {
	block2
    }

introduces another artificial level of complexity by requiring the double
indentation for each block, and makes it more difficult to use the TAB
key for statement indentation.

The same arguments can be made for Pascal, suggesting a similar no-frills
style, and avoiding those large '>'-shaped if statements, which tend to
make it more difficult to find block boundaries, unless the indentation is
done perfectly.
-- 
Dominick Samperi, NYC
    samperi@acf8.NYU.EDU	samperi@marob.MASA.COM
    cmcl2!phri!marob        	uunet!hombre!samperi
      (^ ell)