Code Specification
A single person's software has rarely met (a tribute to independent game developers), the software is done in cooperation with each other, the smallest unit: two people.
Code specification: Different people judge the quality of the code, we need to reference
Code style guide
The provisions of the text, it is important
Principles: concise and readable, unambiguous
It should be seen that a naming and semantic type variable
Hungarian notation: to variables in a meaningful prefix. For strongly typed language unnecessary
Pascal: all words capitalized
Camel: the first word lowercase, and the rest follow Pascal word
Function: verb or verb-object combined
Note
Complex function header comments should be placed
Comments should only use ASCII code
Misleading comment is worse than no comment
Avoid redundant comments
Code design specifications
Specifications on the general principles involved in module relations
function
Do one thing and do a good job
goto
Function best with a single outlet for this purpose, you can use goto
? ? I had previously been told to avoid using goto
Error Handling
Verify the correctness of the parameters
Use Assert
How to deal with in C ++ class
The use of class
Class to encapsulate using object-oriented concepts and polymorphism
Pointer is passed, to avoid transmitting entity value
For an explicit class constructor and destructor functions, to avoid the establishment of a global entity, and because they do not know when to create Elimination
Use only the class when necessary
Encapsulated data only, you can use struct
Use only the type of inheritance, if necessary
About the data members and methods
In accordance with the public, protected, private order to illustrate the members of the class
Virtual functions to achieve polymorphism; virtual functions only when necessary; if you want to achieve a type of polymorphism, the destructor in the base class virtual function should be (for reasons not clearly understood, in order to prevent forgetting destructor write it in a subclass, are not very familiar for c ++)
Data members m_name; do not use public data members; with inline access functions, taking into account packaging and efficiency
new and delete
Check the return value of new, new is not necessarily successful
Do not check for NULL pointer when released
Operators
Do not do things outside of the standard semantics
Indeed redefinition if necessary
Need for efficient
Code Review
- If the code in the framework of the "Code norms" in the right to solve the problem
- Self-review, peer review, the review team
- purpose
- Find a code error: coding error, do not meet the standard place, logic and arithmetic errors, potential errors and regression error stars
- Way familiar with the project code
- After review
- Correct obvious errors
- Recording can not be quickly corrected the error
- Record error often committed themselves to promote self-review
- Code review checklist (note the need for this stuff)
Pair Programming
Driver & Navigator
Feeling helps to avoid low-level errors
This part of psychology, communication skills, etc.
The importance of teamwork
Finishing notes
inline
In C ++, the function may be defined at the time, in front of the return value with the keyword inline type, increasing the inline keyword function is called "inline function."
- Inline function and the difference between the ordinary function: When the statement is inline function calls within the compiler process, not compile the statement to a function call instruction, but directly to the function code for the entire body is inserted at a call statement, as the entire body of the function at the call was rewritten again the same.
- You do not need to pay the overhead of a function call
- Inline function code should just very simple, quick execution of several statements. Otherwise meaningless
- Statement before calling inline function within the definition of an inline function (ie, the number of whole body) must have appeared, and declared inline functions not only appear.
inline int Max (int a, int b)
{
if(a >b)
return a;
return b;
}
- abnormal
- An exception can not cross the border DLL or processes to convey information, not quite understand the meaning, still need to know
- Exception handling mechanism and unusual expenses
- Do not treated as a logic control program in the main flow with the exception of
- Note that cleaning up data in any place when using an exception