1.CodeStyle specifications
Item |
Specifications |
Description |
Indent |
4 spaces |
If tab is used, the display length will change in different places. |
Row width |
Fixed |
The limit is that the limit is not exceeded when Solution Explorer is not hidden in vs2010. |
Brackets |
Ignore brackets instead of relying on priority |
Clearly express the logical priority in complex conditional expressions |
Broken Line and blank {} line |
Required, cannot be omitted |
One-step debug is required; Clear structure and correspondence |
Underline |
In either of the following scenarios:
- The private member of the class starts with an underscore (_).
- The Event Response Function separates objects and actions
|
|
Case sensitivity |
Type/class/function name in Pascal format Variables are in the camel format. |
Class/type/variable use combination nouns, The function uses verb or dynamic object composite words. |
Note |
- Complex comments should be placed in the function header;
- Annotations are only used to explainProgramWhat to do, why, and what to pay special attention;
- Do not comment on how the program works, which should be clearly reflected in the Code
- Code with obvious similarity should be included in # region # endregion and annotated
|
Annotations should be updated continuously as the program changes |
Naming rules:
Item |
Specifications |
Example |
Private member of the class |
Start with an underscore, followed by an upper case of the first letter and the rest of the first letter. |
_ Startposition |
Public member of the class |
Property indicates that private members must be encapsulated by properties if they require external access. |
Public float startposition { Get; Private set; } |
Class attribute name |
The first letter of all words must be capitalized. |
Startposition |
Other variables except private members of the class |
The first letter is the first letter, and the other letters are the first letter. |
Myprivatevariable |
Class, enumeration, struct name |
The first letter of all words must be capitalized. |
Minisphere |
Namespace name |
The first letter of all words must be capitalized; The name cannot contain underscores. If yes, the name must be specified. |
|
Annotated templates:
File comment |
At the beginning of the file: /*************************************** ************************************\ * Codingcrazy Team @ MSRA-USTC class * * Module name: An unabbreviated name for the module (not the filename) * Abstract: * Description of what this module does * Notes: * [Optional] algorithm description, special case conditions, * References, etc. * * History: * Created on 2010-11-24 by XXX * # Add... * Modified on 2010-11-25 by XXX * # Add... * # Remove... *#... * Modified on 2010-11-26 by XXX *#... \*************************************** ************************************/ |
Function header comment |
Use XML document annotations, that is /// |
Internal function comments |
Always use // |
2. Code Design Specifications
Function: Only one task is required.
Parameter processing: all passed parameters must be assert to ensure correctness.
For example, assert (P! = NULL); Assert (S. length> 3 );
Error Handling: the output code used only for debugging purposes must be nested in the following pre-processing statements.
# If _ daidai_debug _
// Debug-related code
# Endif
TIPS:
- Use Ctrl + K + C to annotate the code into a piece, and CTRL + K + u to cancel the annotation.
- Make good use of code snippets and code wrap:
You can enter # region and press the tab key twice.
Enter fore, press the tab key twice, and then press the tab to modify.
Press # If and then press the tab key twice.
Right-click a piece of code and select surround with... from the menu, and then select try or # region.
- Use F12 and CTRL + '-' to navigate to the code.
- Right-click the refractor menu item. For example, encapsulate field is used to encapsulate Private Members in the class.
- Right-click the reslove menu item to add the namespace.