Changes between Version 9 and Version 10 of MapGuideCodingStandards


Ignore:
Timestamp:
Jul 14, 2008, 11:28:04 AM (16 years ago)
Author:
jbirch
Comment:

more

Legend:

Unmodified
Added
Removed
Modified
  • MapGuideCodingStandards

    v9 v10  
    283283==== Repository ====
    284284
    285 The resource repository used by MapGuide will use the UTF-8 standard for storing strings.
     285The resource repository used by !MapGuide will use the UTF-8 standard for storing strings.
    286286
    287287==== API Boundary ====
     
    369369}}}
    370370
    371 
     371=== ForEach Statements ===
     372
     373A foreach statement should have the following form:
     374{{{
     375#!cpp
     376foreach (var in col)
     377{
     378    statements;
     379}
     380}}}
     381
     382=== While Statements ===
     383
     384A while statement should have the following form:
     385{{{
     386#!cpp
     387while (condition)
     388{
     389    statements;
     390}
     391}}}
     392
     393An empty while statement should have the following form:
     394{{{
     395#!cpp
     396        while (condition);
     397}}}
     398
     399=== Do-While Statements ===
     400
     401A do-while statement should have the following form:
     402{{{
     403#!cpp
     404do
     405{
     406    statements;
     407} while (condition);
     408}}}
     409
     410=== Switch Statements ===
     411
     412A switch statement should have the following form. C# requires a terminating break or goto for each case.
     413{{{
     414#!cpp
     415switch (condition)
     416{
     417    case XYZ:
     418        statements;
     419        break;
     420
     421    case ZYX:
     422        statements;
     423        break;
     424
     425    default:
     426        statements;
     427        break;
     428}
     429}}}
     430
     431Every switch statement should include a default case.
     432
     433=== Try-Catch Statements ===
     434
     435A try-catch statement should have the following format:
     436{{{
     437#!cpp
     438try
     439{
     440    statements;
     441}
     442catch (MgExceptionClass1 e)
     443{
     444    statements;
     445}
     446catch (MgExceptionClass2 e)
     447{
     448    statements;
     449}
     450}}}
     451
     452A try-catch statement may also be followed by `finally` which is always executed.
     453{{{
     454#!cpp
     455try
     456{
     457    statements;
     458}
     459catch (MgExceptionClass1 e)
     460{
     461    statements;
     462}
     463catch (MgExceptionClass2 e)
     464{
     465    statements;
     466}
     467finally
     468{
     469    statements;
     470}
     471}}}
     472
     473=== Return Value ===
     474
     475The use of a single return within a method or function is encouraged.
     476The following structure:
     477{{{
     478#!cpp
     479if (booleanExpression)
     480{
     481    return true;
     482}
     483else
     484{
     485    return false;
     486}
     487}}}
     488should be:
     489{{{
     490#!cpp
     491return booleanExpression;
     492}}}
     493
     494Also,
     495{{{
     496#!cpp
     497if (condition)
     498{
     499    return x;
     500}
     501return y;
     502}}}
     503
     504should be:
     505{{{
     506#!cpp
     507        return (condition ? x : y);
     508}}}
     509
     510=== Expressions With !== ===
     511
     512The following order should be used because it will help catch the accidental use of "!=" when "!==" was intended at compile time:
     513{{{
     514#!cpp
     515if (constant == variable)
     516{
     517    // do something
     518}
     519else
     520{
     521    // do something else
     522}
     523}}}
     524