C bites / programming style [if

Alexis Dimitriadis alexis at reed.UUCP
Tue Sep 17 05:15:19 AEST 1985


> > In my mind, the braces are associaed with the 'if' statment, and so
> > they should be indented at the same column as the 'if'.  I look for the
> > closing brace in the same column to be a sort of 'statement terminator'

> Well, in my mind the braces are simply grouping the statements 'under'
> the if.

  The above difference of opinion has in the past been called a religious
argument, with good reason.  Last time it was discussed, Owen Beckley,
then at uw-june, conducted a poll of the preferred brace alignment and 
commenting style.  While it may not prove anything, it should give everybody
an idea of how many people will never agree to use one's own indenting style.

  So, without further ado,
---------------------------

Well, here are the results to my C indentation/commentation survey.  As a 
reminder, here are the catagories that I posted.


Block indentation:

1)	if (a == b) {                    2)	if (a == b) {
	    statement1;                 	    statement1;
	    statement2;                 	    statement2;
	}                               	    }

	
3)	if (a == b)                      4)	if (a == b) 
	{                               	    {
	    statement1;                 	    statement1;
	    statement2;                 	    statement2;
	}                               	    }

	
5)	if (a == b)                      6)      other, please specify
	    {
		statement1;
		statement2;
	    }


"End" comments:

a)	if (a == b)                     b)	if (a == b) 
	    {                           	    {
	    statement1;                 	    statement1;
	    statement2;                 	    statement2;
	    } /* if */                  	    } /* end if */ 


c)	none                            d)      other, please specify


e)      no vote (I added this after receiving many "no votes")


If the persons "other" vote only differed from one of the given choices
by the number of indention spaces, I moved it to the appropriate catagory.
This would be a user setable option.


                         Indentation Type           Totals for Comment type
        e matching
        braces.

    4)  This one was chosen by most people that hinted that they were Pascal/
        Algol/ PL/I programmers.  It leaves the left margin fairly clear,
        is easy to line up the braces with, and puts the braces with the 
        compound statement and not the if.

    5)  This one was chosen for its readability and reasons like 4.

    6)  These "others" were quite varied and some were very strange.
----------------------
To the above let me add a couple of comments of my own:

- Note that although the K&R style is the clear winner, more than half
  of the respondents (fifty-six percent) use a different indenting style.

- Of those, most use a style that aligns the braces with each other
  without eating up an extra tab (style 3 or 4).

Alexis Dimitriadis
-- 
_______________________________________________
  As soon as I get a full time job, the opinions expressed above
will attach themselves to my employer, who will never be rid of
them again.
				alexis @ reed
    {decvax,ihnp4,ucbcad,uw-beaver}!tektronix!reed.UUCP
#! rnews 772
Relay-Version: version B 2.10 5/3/83 based; site houxm.UUCP
Posting-Version: version B 2.10.2 (Tek) 9/28/84 based on 9/17/84; site orca.UUCP
Path: houxm!vax135!cornell!uw-beaver!tektronix!orca!davecl
From: davecl at orca.UUCP (Dave Clemans)
Newsgroups: net.micro.atari
Subject: Re: Re: Dbl clik on ST & Last DTACK
Message-ID: <1733 at orca.UUCP>
Date: Mon, 16-Sep-85 13:08:08 EDT
Article-I.D.:     orca.1733
Posted: Mon Sep 16 13:08:08 1985
Date-Received: Tue, 17-Sep-85 07:38:57 EDT
References: <202 at uw-june> <1741 at hao.UUCP>
Organization: Tektronix, Wilsonville OR
Lines: 5

Double click means to press the left mouse button twice in rapid succession.
The GEM desktop completely ignores the right mouse button
(but user applications can of course use both mouse buttons).

dgc
#! rnews 1814
Relay-Version: version B 2.10 5/3/83 based; site houxm.UUCP
Posting-Version: version B 2.10.2 9/5/84; site reed.UUCP
Path: houxm!vax135!cornell!uw-beaver!tektronix!reed!purtell
From: purtell at reed.UUCP (Lady Godiva)
Newsgroups: net.singles
Subject: Re: Women and Horror Film



More information about the Comp.lang.c mailing list