Changes between Initial Version and Version 1 of MapGuideCodingStandards


Ignore:
Timestamp:
Jul 14, 2008, 10:53:13 AM (16 years ago)
Author:
jbirch
Comment:

Partial progress on coding standards wikification. Don't want to lose work...

Legend:

Unmodified
Added
Removed
Modified
  • MapGuideCodingStandards

    v1 v1  
     1= !MapGuide Coding Standards =
     2
     3This document was originally based on a document maintained by Bruce Deschant, entitled !MapGuide Coding Standards and Guidelines, rev 1.6, last updated July 7, 2008.
     4
     5'''Revision History'''
     6
     7||'''Revision'''||'''Date'''||'''Author'''||'''Comment'''||
     8||1.6||July 7, 2008||Bruce Deschant||Initial public revision||
     9
     10[[PageOutline(3,Table of Contents,inline)]]
     11
     12== Introduction ==
     13
     14This document describes the coding guidelines to be used for the !MapGuide project. Here are a few reasons why we need coding guidelines:
     15 * Most of the cost of software goes to maintenance
     16 * The maintenance is done by many different individuals over the lifetime of a given software product and not the original developer.
     17 * Guidelines improve readability of the software and help make the learning curve of new developers easier.
     18
     19== Consistency with .NET ==
     20
     21Parts of !MapGuide will be based on Microsoft's .NET framework, and therefore we should understand and follow the standards/design guidelines recommended by Microsoft for .NET.  In Visual Studio .NET, you can find these under Design Guidelines for Class Library Developers.  Alternatively, you can go to the help index and navigate to:
     22
     23{{{
     24
     25   Visual Studio .NET
     26      .NET Framework
     27         Reference
     28            Design Guidelines for Class Library Developers
     29
     30}}}
     31
     32The guidelines discuss topics such as naming conventions, how to decide whether something should be a property or method, proper use of enumerations, delegates, and events, and lots of other things.  You should become generally familiar with these guidelines.
     33
     34== Class Names ==
     35
     36All class names should be prefixed with “Mg”.
     37
     38Examples:
     39
     40{{{
     41#!cpp
     42class MgServerSelectFeatures
     43class MG_SERVER_MAPPING_API MgMappingUtil
     44class MG_SERVER_RENDERING_API MgServerRenderingService : public MgRenderingService
     45}}}
     46
     47== Class Variables ==
     48
     49Any variable that needs to be visible outside of a class will expose itself via accessors (either protected, public, or internal).  In general we only use private member variables unless there is a very good reason for any other type.  Consequently, variables may be accessed directly only inside the class where they are defined.  All other access is done through the accessor.  This will help to support multi-threading and distributed objects.
     50
     51== Documentation Standard ==
     52
     53=== 5.1 .NET/C++ ===
     54
     55When you define a new public class, property, or method, you must follow the XML Doc standard.  Typing three slashes “///” just before a class/property/method declaration will bring up a skeleton XML Doc header in .NET, for C++ you will have to enter this.  You then simply need to add information in the different fields.  Note that if you fail to add the XML Doc header for .NET, the code may not compile (this is an option that we will enable for all our projects).
     56
     57XML Doc Standard example:
     58{{{
     59#!cpp
     60///<summary>
     61///Summary of CanIgnoreElement.
     62///</summary>
     63///<remarks>
     64///
     65///</remarks>
     66///<param name="element">
     67///Description of parameter element
     68///</param>
     69///<param name="sFileName">
     70///Description of parameter sFileName
     71///</param>
     72/// <returns></returns>
     73private bool CanIgnoreElement(Element element, string sFileName)
     74}}}
     75
     76=== General ===
     77
     78It’s important to stay disciplined to avoid getting into the habit of "coding now, documenting later".  Whenever you add or modify any classes/properties/methods, you must provide/update the documentation as well.  The documentation you write needs to be of sufficient quality so that someone other then you can work with it.  We as developers are ultimately responsible for providing the technical information that is required to fully document a class/property/method – not someone else.  We’ll refer to this documentation as "seed documentation", and its content should be as close as possible to the end-user reference documentation.
     79
     80Note that private variables/properties/methods should be documented as well (for code readability).  In this case, however, simply use the normal C++ comment style, e.g.
     81{{{
     82#!cpp
     83// the shoe size, including half-sizes
     84private float shoeSize
     85}}}
     86