Coding rules of specialized programming
Zheng Liqun · Yesky
Foreword: To develop a specialized software product, in the coding phase, you must strictly implement a certain code development criterion, which will reduce the implicit error of the program while making the internal structure of the program. Thus, there will be a small error, the quality of maintenance, so that the team's teamwork and professionalization have greatly improved. This is a recognized criterion in software development and a specific application of software engineering in coding stages. I have discussed this problem with many programmed friends. I have accumulated some experience in the actual development. Now I will construct the code rule I have experienced: Content: The applicable platform is 32-bit windows, language is C -based language (C , VC ...) one. Improve the readability requirements: 1. For each file you wrote, add relevant standardized annotations, generally should include: file role, version number, author and time, etc. 2. Write detailed comments for your defined class, including the author, time, version revision, basic algorithm, and detailed explanation of member variables. 3. Write a detailed note for each function you define, including the input / output parameter description, return value description, function function description. *********************************************************** ***************************** 4. In the interior of the function, the length of the annotation (division function module), the short boss annotation (describing each step of implementation) is combined with the sentence after the sentence (indicating the meaning of the important sentence), and the clear function is implemented. File: // ************* The following functions are implemented below **************** File: // ... operation (1) . .............. .............. file: // This action is .... File: // Perform ... Operation (2). 5. All named (class, functions, variables ..) require significance to be clear and easy to understand. 6. Avoid using uncertainwords such as numbers and true / false in the code, try to use meaningful string values. Const Static Word W_Person_Num = 10; Bool BmustProcess = true; 7. It is best not to appear to "IF (TEST, etc." logic judgment statement, with the following instead of: if (true == test) IF (personnnu == test) IF (NULL! = TEST). 8. Don't use goto. 9. Don't write too long if () {...}, for () {...}, while (...) {} or too many nested. 10. The above longevity is added at the end of the range. If // For cycle ends 11. A variety of variables and function class members variables are distinguished on the name: m_ *, global variable: g_ *, API function :::. Two. Cancellation of hidden dangers in programs to reduce coupling: 1. Only those referenced by other classes are defined as a PUBLIC type function.
2. It is best not to use the public type member variable (classic replacement method: for this variable). 3. It is best not to use global variables. Description: You can specify in the C * App class, then use AFXGetApp () -> *** to use increased aggregation: 1. A common member function cannot return a pointer or a very quite reference for the member variable of the class. 2. Using a class, where possible (class accessible only by pointer or category), the class's header file should be included in the user's .cpp file, increase the encapsulation while avoiding repeated inclusion (class as a self) in the case of). If you must include this class file in the user's .h file, you should use the IFDEF ... statement to avoid repeating it. 3. The function of the function should be single, the meaning of the parameters should be single. Basic rules: 1. Try to use parentheses to clearly calculate the order of the expression. 2. Use reference parameters instead of pointer parameters (clear semantics; to ensure that the transmission is initialized; keepivity). 3. The initial value should be assigned when the variable is defined. 4. Use null == *, false == *, instead of * == null, * == false ... Description: Avoid pen error 5. Use null; empty statement. While (---) null; file: // Avoid errors (mishand semicolon) 6. Use Const Static instead #define (using the type of compiler). 7. The destructor of the class containing the virtual function must be a false prefix function. 8. When programming under the VC, set the compile option "Warning Level" to "Level 4" (start all warning functions of the compiler). 9. Before you have prepared Return, it is best to apply the system default value. 10. Debug version with the Release version. #Ifdef debug #define debug ..... #ndif #undef debug 11. When installing, remove all our custom DLL, LIB, OCX, registry key .... Memory related issues: 1. When allocating memory (such as graphics ...), you should assign a value to a function of MEMSET (.). EXM1: Bitmap BM;
:: MEMESET (& BM, 0, SIZEOF (Bitmap);
EXM2:
TCHAR TSZNAME [MAX_PATH];
:: MEMESET (TszName, 0, SizeOf (Tchar) * max_path; 2. All places involving memory allocation must determine whether to assign success and perform corresponding processing. 3. Use New and Delete to assign and release stack memory (safer; easy to test memory leaks). 4. Pointer Problem: When defining Pointer: Point Pointer NULL is initialized (why: otherwise if (null == *) will fail). When using Pointer at any time, it will first judge whether it is empty, and it should be handled accordingly. Before allocating memory, first judge whether it is non-empty, and delete it off for non-empty first. After allocating memory, it is immediately judged whether or not to assign success (Pointer! = NULL) to process the air. When the pointer is released, it is judged whether it is not empty, and it is not empty, and then it will be removed, and then empty (whose empty pointer will not do anything when using Delete). 5. After the program is completed, use Debug to check if there is a memory leak; whether there is a global or local unsealed memory in the software analysis program of the resource monitor. three. Common agreement, unified form, convenient for multiplayer cooperation (most of them are currently general agreements). 1. Define structure: typedef struct tagstructName {....} structname; 2. Define constants: const static word w_person_num = 10; 3. Naming Conventions: XX prefix xx class prefix classCbool-> BOOLb member variables m_BYTEby global variable g_char-> TCHARtchAPI :: WORDw function pointer p / lpDWORDdw handle hint-> LONGlLPTSTRlpszfloatfLPCTSTRlpcszDOUBLEdbPOINTPt (diff for p) RECTrt