Changeset 605


Ignore:
Timestamp:
Apr 9, 2007, 4:24:52 AM (19 years ago)
Author:
Steven Levine
Message:

Update

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/CodingStyle.txt

    r459 r605  
    11
    2 Coding Style Guide
    3 ==================
     2Coding Style Guidelines
     3========================
    44
    55Line lengths
     
    77  Try to keep lines less than 80 characters.
    88
    9   Break lines after logical separators
     9  Break lines after logical separators.
    1010
    11   Vertically align like constructs
     11  Vertically align like constructs.
     12
     13    func(arg1,
     14         arg2);
    1215
    1316Indents
     
    1720  Place function definition } in column 1
    1821
    19   Intent nested constructs by 2 characters
     22  Indent nested constructs by 2 characters
    2023
    2124  void func()
    2225  {
    23     stmt
     26    statement;
    2427    if (expr)
    25       stmt2
     28      statement2;
    2629  }
    2730
    2831Tabs
    2932
    30   Use only 8 column tabs
     33  Use only 8 column tabs.
    3134
    3235Layouts
    3336
    3437  if (expr)
    35     statement
     38    statement;
    3639
    37   // If expr and statement are brief
    38   if (expr) statement
     40  // If expr and statement are brief single line is OK.
     41  if (expr) statement;
     42
     43  // If statment is long, split logically and use braces.
     44  if (expr) {
     45    statement_part1...
     46      restoflongstatement;
     47  }
     48
     49  if (expr)
     50    statement;
     51  else
     52    statement2;
    3953
    4054  if (expr1) {
     55    statement1;
     56    statement2;
     57  }
     58  else if (expr2) {
    4159  }
    4260  else {
    4361  }
    4462
    45   // If expression must be wrapped
    46   // align like constructs vertically
     63  // If expression wrapped, align like constructs vertically.
    4764  if (expr1 &&
    4865      expr2))
    4966  {
     67  }
     68
     69  // Prefer expression sense that places shorter statement list first.
     70  if (!expr)
     71    ReportError();
     72  else {
     73    statement1;
     74    ...;
     75    statementn;
    5076  }
    5177
     
    6288Variable definitions
    6389
    64   Define one per line
     90  Define one variable per line.  They are easier to find and understand.
    6591
    6692    INT a;
    67     INT b;
     93    INT *pb;
    6894
    6995  not
    7096
    71     INT a,b;
     97    INT a,*b;
    7298
     99Variable naming
     100
     101  Prefer Hungarian notation and CamelCaps for global variables.
     102
     103    BOOL fAGlobalFlag;
     104
     105  Prefer lower case and underscores for local variables.
     106
     107    BOOL is_ok;
     108 
     109  Local varibles can be short as long as meaning is clear.
     110
     111    BOOL ok;
     112
     113  Underscores can be omitted if name remains readable.
     114
     115    USHORT maxcnt;
     116 
    73117Spaces
    74118
    75   Separate keywords from leading paren with 1 space
     119  Separate keywords from leading paren with 1 space.
    76120
    77     if (expr) dothis
     121    if (expr) statement;
    78122
    79   No space between function name and leading paren
    80   No space between last arg and trailing paren
     123  No spaces between function name and leading paren.
     124  No spaces between last arg and trailing paren.
    81125
    82126    func()
    83127
    84   Follow separating commas and semicolons with a space
     128  Follow separating commas and semicolons with a space.
    85129
    86130    x = func(a, c)
    87131
    88   Surround binary operators with a leading and trailing spaces
     132  Surround binary operators with a leading and trailing spaces.
    89133
    90134    x = a + b
    91135
    92   Try to avoid spurious internal and trailing whitespace
     136  Try to avoid spurious internal and trailing whitespace.
     137
     138Expressions
     139
     140  Do not use superfluous parens.
     141
     142  Prefer
     143
     144    return 0;
     145
     146  to
     147
     148    return (0);
     149
     150  Do not use superfluous parens when operator precedence with do the
     151  right thing.
     152
     153  Prefer
     154
     155    if (a & mask && c)
     156
     157  to
     158
     159    if ((a & mask) && c)
     160
     161  Avoid nested ternary conditionals (i.e. ? :).  They are hard to read and
     162  rarely generate better code than switch or if statement.
    93163
    94164Memory
     
    100170
    101171 - Use xfree rather than free
     172
     173 - Buffer overflow possible, check for it.
    102174
    103175Windows
Note: See TracChangeset for help on using the changeset viewer.