Qiming's profile陆其明 - 逐日PhotosBlogListsMore Tools Help
    3/16/2005

    已经影响了我3年的Coding Standard

    MSI coding standard

                                                                By John Huang

    1. Objective
      1. To make the code easy to understand, by the original developer, and by other developers who utilize the code.
      2. To make the code easy to maintain, by the original developer, and by other developers, and to keep a consistent style over the life cycle.
      3. To make the code easy to type.
    2. Class name
      1. Regular class should start with C. For example, CVideoFile.
      2. Utility classes, which contains only static members, should start with U. For example, UStringUtils.
      3. Stack classes, which use its constructor and destructor to store and restore some states, should start with St. For example, StWaitCursor.
      4. Each class should reside in one .cpp file and one .h file. Each file should contain only one class. The file name should be classname.cpp and classname.h. Do not omit the prefix C, U, or St.
      5. The .h file should be scoped with

    #ifndef _H_classname_
    #define _H_classname_

    #endif

    1. Function name
      1. Function names should be complete words instead of abbreviations.
      2. Each word in the function name should start with capital letter.
      3. Function names should be descriptive.
    2. Parameters
      1. Each parameter should use prefix to indicate whether it is input value, or output value, or both

                          i.      Use “in” to indicate it is an input value. 
                          ii.      Use “out” to indicate it is an output value. 
                          iii.      Use “io” to indicate it is both input and output.

      1. There is no need to use prefix to indicate the data type.
      2. After the prefix, the parameter name should be complete words instead of abbreviations.
      3. Each word should start with capital letter.
      4. Each parameter should contain one meaning only.
    1. Return value
      1. The return value should contain one meaning only.
      2. If multiple return values are needed, use pointer or reference parameters with “out” as prefix.
      3. Use enum type for return values that are flags.
      4. If the meaning of a return value is not obvious, it must be documented in the .h file.
    2. Function body
      1. Block start and block end ( “{“ and “}”) should be on their own line.
      2. The block end should match its block start vertically.
      3. Normally, a function should contain less than seven lines of code.
      4. A function should never exceed the viewable area of VC. (The complete function must be viewable in VC without scrolling)
      5. Local variables should be declared just before they are used (as late as possible).
      6. Local variables should be complete words instead of abbreviations.
      7. The first word of local variable name should start with lower case. Other words in the name should start with upper case. For example, “newColor”.
    3. Project
      1. Library projects should have a name starting with “Engine”.
      2. Projects containing internal data logic should start with “Data”.
      3. Projects containing user interface code should start with “View”.
      4. Projects that build the final exe should start with “App”.
      5. Resource projects should contains the language resource should start with “Language”.
      6. Projects that build filters should start with “Filter”.
      7. App projects should contain as little code as possible.
    4. Text Format
      1. Use standard VC default settings for code editor format.
      2. Do not use third party code editors to avoid different look on different PCs.
      3. The width of the code should fit within the VC code editor window without horizonal scrolling.
      4. The vertical length of the each function should fit within the VC code editor window without vertical scrolling.
    5. Code
      1. NEVER use “goto”.
      2. Do not “return”, “break” or “continue” in the middle of a loop. They make the code harder to understand, and easier to have mistakes.
      3. Do not “return” in “if…else…” unless there is no other code after the “if…else…” blocks.
    6. Assembly
      1. Assembly code should use MS assembler.
      2. Assembly code should be accompanied by corresponding c code.

    Comments (1)

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    No namewrote:

    Hi,Do you need advertising displays, screen advertisings, digital sign, digital signages and LCDs? Please go Here:www.amberdigital.com.hk(Amberdigital).we have explored and developed the international market with professionalism. We have built a widespread marketing network, and set up a capable management team dedicated to provide beyond-expectation services to our customers.

    amberdigital Contact Us

    E-mail:sstar@netvigator.com
    website:www.amberdigital.com.hk
    alibaba:amberdigital.en.alibaba.com[ebdbc

    Sept. 10

    Trackbacks (1)

    The trackback URL for this entry is:
    http://jemylu.spaces.live.com/blog/cns!E1C9F572B6A2D19!229.trak
    Weblogs that reference this entry