Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2001:
[Freeciv-Dev] Re: Coding Guideline Updated RFC
Home

[Freeciv-Dev] Re: Coding Guideline Updated RFC

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv development list <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] Re: Coding Guideline Updated RFC
From: Andrew Sutton <ansutton@xxxxxxx>
Date: Mon, 26 Nov 2001 12:29:41 -0500

On Monday 26 November 2001 10:51 am, you wrote:

1B 2B 3B 4A 5A 6A 7(see comment) 8A

> > /***************
> >  * 1: init vars
> >  ***************/
>
> when variable is initialised immediately it's so much clearer what it's
> meaning is.  especially if it's not going to change throughout the
> function's body

i thought that C - at least in its pure form didn't allow you to initialize 
values on the stack like that: they have to be declared first - reason being: 
it's not C++ there's no such thing as constructors in C. for C, i really like 
seeing all the variables declared and commented:

int some_int;           /* used for... */
float some_float;       /* used for ... */

> > /****************
> >  * 3: comments
> >  ****************/
>
> B does not depend on the line's length

right.. comment before code. except in structural declarations where the 
comment should be on the same line for easier readibility.

struct foo
{
        int bar;        /* blah blah blah */
};

> > /******************************************
> >  * 5: unnecessary braces after conditionals
> >  ******************************************/
>
> A is more orderly but takes more space...

are you really that worried about the extra line ;) IMHO there should always 
be braces around any compound statement like that. helps visually group the 
statements to that expression.

>
> > /****************************************************
> >  * 6: unnecessary braces after conditionals with else
> >  ****************************************************/
>
> A is better

yup. see comment on 5.

> > /****************************
> >  * 7: merge declaration lines
> >  ****************************/
>
> declarations should by grouped by their meaning if possible
> besides what if there are too many ints to fit on one line?

actually, you should separate out all declarations so they have their own 
line. i know its redundant and people don't like it but it will make complex 
functions oh so much more readable. especially if they declare alot of 
variables. then, you get the option of commenting them as they're declared:

int foo()
{
        int a;          /* used for ... */
        int b;          /* used for ... */
        int c;          /* used for ... */

        // code...
}

>
> > /*************************
> >  * 8: double dereferencing
> >  *************************/
>
> A
> why not

yup.

Andrew Sutton
ansutton@xxxxxxx


[Prev in Thread] Current Thread [Next in Thread]