MSI coding standard
By John Huang
- Objective
- To make the code easy to understand, by the original developer, and by other developers who utilize the code.
- 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.
- To make the code easy to type.
- Class name
- Regular class should start with C. For example, CVideoFile.
- Utility classes, which contains only static members, should start with U. For example, UStringUtils.
- Stack classes, which use its constructor and destructor to store and restore some states, should start with St. For example, StWaitCursor.
- 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.
- The .h file should be scoped with
#ifndef _H_classname_
#define _H_classname_
…
#endif
- Function name
- Function names should be complete words instead of abbreviations.
- Each word in the function name should start with capital letter.
- Function names should be descriptive.
- Parameters
- 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.
- There is no need to use prefix to indicate the data type.
- After the prefix, the parameter name should be complete words instead of abbreviations.
- Each word should start with capital letter.
- Each parameter should contain one meaning only.
- Return value
- The return value should contain one meaning only.
- If multiple return values are needed, use pointer or reference parameters with “out” as prefix.
- Use enum type for return values that are flags.
- If the meaning of a return value is not obvious, it must be documented in the .h file.
- Function body
- Block start and block end ( “{“ and “}”) should be on their own line.
- The block end should match its block start vertically.
- Normally, a function should contain less than seven lines of code.
- A function should never exceed the viewable area of VC. (The complete function must be viewable in VC without scrolling)
- Local variables should be declared just before they are used (as late as possible).
- Local variables should be complete words instead of abbreviations.
- 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”.
- Project
- Library projects should have a name starting with “Engine”.
- Projects containing internal data logic should start with “Data”.
- Projects containing user interface code should start with “View”.
- Projects that build the final exe should start with “App”.
- Resource projects should contains the language resource should start with “Language”.
- Projects that build filters should start with “Filter”.
- App projects should contain as little code as possible.
- Text Format
- Use standard VC default settings for code editor format.
- Do not use third party code editors to avoid different look on different PCs.
- The width of the code should fit within the VC code editor window without horizonal scrolling.
- The vertical length of the each function should fit within the VC code editor window without vertical scrolling.
- Code
- NEVER use “goto”.
- Do not “return”, “break” or “continue” in the middle of a loop. They make the code harder to understand, and easier to have mistakes.
- Do not “return” in “if…else…” unless there is no other code after the “if…else…” blocks.
- Assembly
- Assembly code should use MS assembler.
- Assembly code should be accompanied by corresponding c code.
阅读(634) | 评论(0) | 转发(0) |