braces (was: Latest indent request)

Mark Nudelman mark at UNIX386.Convergent.COM
Fri Dec 16 09:16:14 AEST 1988


In article <14020049 at hpisod2.HP.COM>, decot at hpisod2.HP.COM (Dave Decot) writes:
> So close!  However, this really should be:
> 
> main (argc, argv)
> int argc;
> char *argv[];
> {
>     int foo;
>     char bar;
> 
> 	if (expr)
> 	{
> 		while (cond)
> 		{
> 		}
> 	}
> }
> 
> Dave Decot
> hpda!decot

Oh, you *almost* got it!  It's really supposed to be like this:

main(argc, argv)
	int argc;
	char *argv[];
{
	int foo;
	char bar;

	if (expr)
	{
		while (cond)
		{
		}
	} else if (expr)
	{
		switch (expr)
		{
		case 0:
			break;
		default:
			break;
		}
	} else
	{
		func(0);
	}
	return (1);
}

While we're arguing style religion, there are of course many other
issues besides indentation and braces.  Altho it would seem that
there aren't many possibilities, I often find I can identify the 
author of a piece of code simply by the spacing/indentation style.
This is what I use:
   (Anyone else caught using it will be prosecuted :-)

1. One space between if/while/return and the left parenthesis.
   (And the expr after return must be surrounded by parentheses.)
2. No space between function name and the left parenthesis.
3. Space before and after arithmetic operators (+,-,*,/,%,>>,&,|, etc.)
4. Two spaces after each semicolon in a for statement;
   e.g. "for (i = 0;  i < MAX;  i++)"
5.	/*
	 * Comments go like this, with the same indentation
	 * as the code they describe.
	 */

For some reason, code which doesn't follow 1 and 2 really annoys me.

Mark Nudelman
{sun,decwrl,ihnp4!hplabs}!pyramid!ctnews!UNIX386!mark



More information about the Comp.unix.wizards mailing list