Changes between Version 8 and Version 9 of MapGuideCodingStandards


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

work-saving commit...

Legend:

Unmodified
Added
Removed
Modified
  • MapGuideCodingStandards

    v8 v9  
    198198}}}
    199199
    200 
     200== IDE Settings ==
     201
     202It is recommended that you use Visual Studio .NET for software development on Windwos and it helps if some settings are the same for all users.  Here are the ones you should make sure are set.
     203
     204Under Tools/Options/Text Editor/All Languages/Tabs, make sure the tab size is set to 4 and that the ‘Insert spaces’ option is turned on.  The use of spaces everywhere rather than a mix of tabs and spaces has the following advantages:
     205
     206 1. It reduces the number of non-essential differences that show up when comparing files
     207   * If I have my editor settings set to use spaces and I edit an area that contains tabs, Visual Studio will sometimes replace the tabs with spaces
     208 1. It prevents columns from lining up evenly
     209   * File comparison tools may treat the width of tabs & spaces unevenly (1 tab does not exactly equal 4 spaces)
     210   * Viewing a source file in Notepad is even worse: a tab is the equivalent of about 8 spaces
     211
     212== Stylistic Guidelines ==
     213
     214=== General ===
     215
     216Use the next-line convention for curly braces:
     217{{{
     218#!cpp
     219public void Foo()
     220{
     221}
     222}}}
     223
     224Another coding standard for C# is to preface all references to instance variables/properties/methods with the “this” keyword.  For example:
     225{{{
     226#!cpp
     227public void Foo()
     228{
     229    // update an instance member variable
     230    this.index = 0;
     231
     232    // call an instance member function
     233    this.Foo();
     234}
     235}}}
     236
     237From a stylistic viewpoint, this makes it very easy to distinguish which variables are member variables and which have temporary scope.  In C++ this is typically done by prefixing names of member variables using “m_” and therefore the keyword “this” is not required. 
     238
     239All static variables are named using Pascal casing according to the .NET standard.  When referencing static constants or methods, always prefix it using the actual name of the class defining the constant or static method.  For example:
     240{{{
     241#!cpp
     242public class MgFoo1
     243{
     244    /// <summary>
     245    /// The max iterations to use.
     246    /// </summary>
     247    public int maxIter;
     248
     249    /// <summary>
     250    /// Default value for max iterations.
     251    /// </summary>
     252    static public int defaultMaxIterations = 10;
     253
     254    ...
     255}
     256
     257public class MgFoo2 extends MgFoo1
     258{
     259    ...
     260
     261    this.maxIter = this.defaultMaxIterations;  // wrong – not an instance variable
     262    this.maxIter = MgFoo2.defaultMaxIterations;  // wrong - subclass doesn't declare it
     263    this.maxIter = MgFoo1.defaultMaxIterations;  // correct
     264
     265    ...
     266}
     267}}}
     268
     269=== Compiler Warning ===
     270
     271This guideline strongly encourages all compiler warnings to be treated as errors and therefore they should be fixed.
     272
     273=== Strings ===
     274
     275==== Internally ====
     276
     277For the !MapGuide project the internal string format to use will be wstring. For .NET development the String class will be used.
     278
     279==== Across Wire ====
     280
     281The UTF-8 standard will be used for transmitting strings across the wire between any of the !MapGuide products (client, web tier, and server).
     282
     283==== Repository ====
     284
     285The resource repository used by MapGuide will use the UTF-8 standard for storing strings.
     286
     287==== API Boundary ====
     288
     289!MapGuide will use the following string format for API boundaries in the web tier and the server:
     290{{{
     291!#cpp
     292const wstring&
     293}}}
     294
     295=== Break and Goto ===
     296
     297Goto and break make the code very hard to read. I cannot believe that C# supports goto!!!
     298The guideline is to avoid using break statements inside loops and to forbid the use of goto.
     299
     300=== If, Else-If, Else Statements ===
     301
     302The if-else statements should have the following form:
     303{{{
     304!#cpp
     305if (condition)
     306{
     307    statements;
     308}
     309
     310if (condition)
     311{
     312    statements;
     313}
     314else
     315{
     316    statements;
     317}
     318
     319if (condition)
     320{
     321    statements;
     322}
     323else if (condition)
     324{
     325    statements;
     326}
     327else
     328{
     329    statements;
     330}
     331}}}
     332
     333=== For Statements ===
     334
     335A for statement should have the following form:
     336{{{
     337#!cpp
     338for (initialization; condition; update)
     339{
     340    statements;
     341}
     342}}}
     343
     344An empty for statement
     345{{{
     346#!cpp
     347        for (initialization; condition; update);
     348}}}
     349
     350Variable declaration inside for statement should NOT be done.
     351
     352Don’t do this:
     353{{{
     354#!cpp
     355for (int i=0; i<10; i++)
     356{
     357    statements;
     358}
     359}}}
     360
     361Do this instead:
     362{{{
     363#!cpp
     364int i=0;
     365for (i=0; i<10; i++)
     366{
     367    statements;
     368}
     369}}}
     370
     371