[Freeciv-Dev] Re: Coding Guideline Updated RFC
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
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
- [Freeciv-Dev] Re: PATCH: AI cleanup Version 2, (continued)
- [Freeciv-Dev] Re: PATCH: AI cleanup Version 2, Petr Baudis, 2001/11/25
- [Freeciv-Dev] Coding Guideline, Gregor Zeitlinger, 2001/11/25
- [Freeciv-Dev] Coding Guideline RFC, Gregory Berkolaiko, 2001/11/25
- [Freeciv-Dev] Re: Coding Guideline RFC, Greg Wooledge, 2001/11/25
- [Freeciv-Dev] Re: Coding Guideline RFC, Daniel Sjölie, 2001/11/25
- [Freeciv-Dev] Re: Coding Guideline RFC, Raimar Falke, 2001/11/26
- [Freeciv-Dev] Re: Coding Guideline RFC, Raimar Falke, 2001/11/26
- [Freeciv-Dev] Re: Coding Guideline RFC, Petr Baudis, 2001/11/26
- [Freeciv-Dev] Coding Guideline Updated RFC, Gregory Berkolaiko, 2001/11/26
- [Freeciv-Dev] Re: Coding Guideline Updated RFC, Gregory Berkolaiko, 2001/11/26
- [Freeciv-Dev] Re: Coding Guideline Updated RFC,
Andrew Sutton <=
- [Freeciv-Dev] Re: Coding Guideline Updated RFC, Raimar Falke, 2001/11/26
- [Freeciv-Dev] Re: Coding Guideline Updated RFC, Andrew Sutton, 2001/11/26
- [Freeciv-Dev] Re: Coding Guideline Updated RFC, Mike Kaufman, 2001/11/27
- [Freeciv-Dev] Please vote!, Gregory Berkolaiko, 2001/11/28
- [Freeciv-Dev] Re: Please vote!, Petrus Viljoen, 2001/11/28
- [Freeciv-Dev] Re: Please vote!, Stepan Roh, 2001/11/28
- [Freeciv-Dev] Re: Please vote!, vze2zq63, 2001/11/28
- [Freeciv-Dev] Re: Please vote!, Reinier Post, 2001/11/29
- [Freeciv-Dev] Re: Please vote!, Raimar Falke, 2001/11/29
- [Freeciv-Dev] Re: Please vote!, Reinier Post, 2001/11/29
|
|