Index: doc/CodingStyle =================================================================== RCS file: /home/freeciv/CVS/freeciv/doc/CodingStyle,v retrieving revision 1.2 diff -u -r1.2 CodingStyle --- doc/CodingStyle 2002/08/12 17:14:21 1.2 +++ doc/CodingStyle 2002/08/28 18:12:36 @@ -14,8 +14,11 @@ - An empty line should be placed between two separate blocks of code. -- Spaces should go before and after operators, and after commas: +- Do not use tabs. Indentation should be by two spaces for each level + of code nesting. +- Spaces should go before and after operators, expressions and commas: + int a,b,c; /* bad */ int i, j, k; /* good */ @@ -23,7 +26,7 @@ c=a+b; } -if(foo <= bar) { /* good */ +if (foo <= bar) { /* good */ c = a + b; } @@ -104,8 +107,16 @@ } - After variables are declared, there should be an empty line before the - rest of the function body. + rest of the function body. Always declare variables before the start of + the function body. + + Do not do this: +{ + printf("test"); + char t = '\0'; /* BAD! */ +} + - Merging declarations. Variables do not have to be declared one per line; however, they should only be grouped by similar function. @@ -143,20 +154,25 @@ - In switch statements, braces should only be placed where needed, i.e. to protect local variables. -- In general, [unnecessary] braces should be applied after conditionals: +- Braces shall be used after conditionals: - if(x == 3) { + if (x == 3) { return; } and - if(x == 3) { + if (x == 3) { return 1; } else { return 0; } + not + + if (x == 3) + return 1; /* BAD! */ + ================================ Other stuff ================================ @@ -182,9 +198,9 @@ - Always prototype global functions in the appropriate header file. Local functions should always be declared as static. -- If you send patches, use "diff -u" (or "diff -r -u"). For further - information, see . Also, - name patch files descriptively (e.g. "fix-foo-bug-0.diff" is good, +- If you send patches, use "diff -u" (or "diff -r -u", or "cvs diff -u"). + For further information, see . + Also, name patch files descriptively (e.g. "fix-foo-bug-0.diff" is good, but "freeciv.diff" is not). - When doing a "diff" for a patch, be sure to exclude unnecessary files