10/10/00

A Matter of Style

If you want to start an argument among a group of programmers, there is one question that will always provoke a response. That question is: "What is the correct way to indent a program?" You can optionally add a language here, like C or Java.

Note that I didn't suggest "How do you indent?", because the programmer may be forced to indent against his style by the tools he is using or by company policies. The question as stated will bring out complaints against these standards as well.

For the record, here is how I indent my C/C++/Java code:

int function (string a, int b,
		int c)
{
	int d;
	if (b == c) {
		d = do_something (a, b, c);
	} else if (b > c) {
		d = do_something_else (a, c);
	} else {
		d = do_something_wonderful (a);
	}

	return d;
}

where the intent is that the "int c)" lines up with the "string a" above it. Normally the tabs that I use to indent are set to a smaller size than eight characters, typically three.

Now I know that this is the God-given correct way to indent, and nothing that anyone can say about brace placement, spaces between a function name and the opening parenthesis, or the need (or lack thereof) for braces around single statements will change my mind. That's right: indentation style is equivalent to religion amongst programmers. I know of programmers who will actually reindent code before they work on it, because they have trouble following the flow of control without it obeying their personal idea of the correct style.

Imagine if this attitude carried to other aspects of life.

Hmmm - maybe I need to rethink my analogies a bit. Until then, I'll be happily reformating this routine I got off the Web - I just can't seem to make heads or tails of it the way it is now.

You can respond to my ranting here.


One man's drink is another man's rant.