I. Program style: 1. Strictly adopt the hierarchical program code: The default style of VC is used for each level of indentation, that is, each layer is indented into four cells, and brackets are placed in the next line. The matching braces must be in the same column, and the following rows must be indented by four cells. For example: 2. Position of the prompt message string The prompt string to be given in the program. In order to support development in multiple languages, all other prompts except Temporary Information for debugging must be defined in the resource. 3. Define variables at the beginning of the function as much as possible. Ii. Naming rules: 1. Naming rules for variable names 1. The variable naming rules must use the Hungary rule ". That is, the start letter uses the type of the variable, and the rest uses the English meaning of the variable or the abbreviation of its English meaning. Do not use Chinese pinyin as much as possible, and the first letter of the word should be large. That is, the variable name = the variable type + the meaning (or abbreviation) of the Variable) For non-General variables, add comments during definition. The variable definition may be placed at the beginning of the function as much as possible. See the table below: Bool (bool) starts with B and bisparent Byte (byte) starts with byflag Short (INT) starts nstepcount with N Long (long) starts lsum with L Char (char) starts with C and ccount Float (float) starts with F. Double (double) start with D ddeta Void (void) starts vvariant with V Unsigned int (Word) starts with W wcount Unsigned long (DWORD) starts with DW dwbroad Handle (hinstance) starts with H DWORD starts with DW Start strstring with 'strstring String ending with 0 starts with SZ szfilename
Propose and give naming suggestions for unspecified variable types to the Technical Committee.
② The basic principles for naming pointer variables are as follows: The basic principles for a heavy pointer variable are: "P" + variable type prefix + name For example, a float * type should be expressed as pfstat. The basic rules for multiple pointer variables are as follows: Double pointer: "PP" + variable type prefix + name Triple pointer: "PPP" + variable type prefix + name ...... ③ Global variables start with G _. For example, a global long variable is defined as g_lfailcount, that is, the variable name = g _ + the variable type + the meaning (or abbreviation) of the variable) ④ Static variables start with S _. For example, a static pointer variable is defined as s_plperv_inst, that is, the variable name = S _ + variable type + the meaning (or abbreviation) of the variable) ⑤ A member variable starts with M _. For example, a long member variable is defined as m_lcount. That is, the variable name = M _ + variable type + the meaning (or abbreviation) of the variable) 6. For variables of the enumeration type (Enum), you must use the enumerated variable or its abbreviation as the prefix. In addition, uppercase is required. For example, Enum cmemdays { Emdays_monday; Emdays_tuesday; ...... }; 7. The naming requirements for struct, union, and class variables should be defined in uppercase. The prefix must be added. The internal variable naming rules are consistent with the variable naming rules. The structure generally starts with S. For example, struct scmnpoint { Int NX; // The X position of the vertex Int NY; // The y position of the vertex }; A consortium generally starts with u. For example, Union ucmlpoint { Long lx; Long ly; } Class generally starts with C For example: Class ccmfpoint { Public: Float fpoint; }; The general structure should be defined as a class template for future scalability considerations. For example: Template Class ccmtvector3d { Public: Type X, Y, Z; }; Constant, the constant name (including the wrong encoding), requires that the constant name in uppercase, the constant name in English to express its meaning. For example, # define cm_file_not_found cmmakehr (0x20b) Where cm indicates the category. For const variables, add C _ before the naming rules of variables, that is, C _ + variable naming rules. For example: Const char * c_szfilename; 2. Function naming rules: The function name should be expressed in English as much as possible. Follow the naming rules of the dynamic object structure. In the function name, the verb is in the front and the prefix of the function is added before the name. The function name must be at least eight letters in length. For example: Long cmgetdevicecount (......); 3. function parameter specifications: 1. For parameter names, see variable naming rules. ② In order to improve the program running efficiency, reduce the stacks occupied by parameters, and transmit large-structure parameters, all parameters are transmitted using pointers or references. ③ To facilitate other programmers to identify whether a pointer parameter is an entry parameter or an exit parameter, and to facilitate compiler check errors, the const mark should be added before the entry parameter. For example: ...... Cmcopystring (const char * c_szsource, char * szdest) 4. Introduce function specifications: For a function exposed as a secondary development function from a dynamic library, class prefix + basic naming rules are used to distinguish it from other functions and Windows functions. For example, the function for editing an image in the dynamic library is defined as imgfunctionname (IMG is short for image ). The naming prefixes of the three databases are given: ① For common function libraries, use cm as the prefix. ② Use VR as the prefix for the 3D function library. ③ Use IMG as the prefix for image function libraries. For macro definition, the result code uses the same prefix. 5. Naming rules for file names (including dynamic libraries, components, controls, and engineering files: Naming of file names requires that the content of the file be expressed. The file name must contain no less than five letters. It is strictly prohibited to use file names such as file1 and myfile. Iii. annotation specifications: 1. Function header comments For functions, the following format should be noted in terms of "function", "parameter", "Return Value", "main idea", "Call method", and "date: // Program description starts // ================================================ ========================================== // // Function: delete another string from a string. // Parameter: strbydelete, strtodelete // (Entry) strbydelete: The deleted string (original string) // (Exit) strtodelete: string to be deleted from the previous string. // Return: 1 is returned if you find and delete it. Otherwise, 0 is returned. (If there is an error code for the returned value, // list the error codes ). // Main idea: This algorithm mainly uses the cyclic comparison method to find it from strbydelete // String matching strtodelete, matching multiple strbydelete // There are multiple strtodelete substrings. See: // Name of the book ...... // Call method :...... // Date: start date, for example, 2000/8/21. -- 2000/8/23. // ================================================ ========================================== // Function Name (......) // Program description ended ① For some functions, some of the parameters are input values and some of the parameters are output values. Therefore, the parameters must be described in detail as entry parameters or exit parameters, some parameters with unclear meanings need to be described in detail (for example, when the angle is used as a parameter, it must be indicated that the angle parameter is in the unit of radian (PI) or degree ), variables that are both entry and exit should be both marked at the entrance and exit. And so on. ② Function comments should be placed in the function header file, and the comments should be placed at the same time in the implementation part of the function in the implementation file. ③ In the comments, we should explain in detail the main implementation ideas of the function, especially some of our own ideas. If necessary, we should specify the reasons for the idea. Comments on the source of some simulated functions. ④. In the comments, specify the appropriate call method of the function and the processing method of the returned value. In the comments, we must emphasize the danger of calling, where errors may occur. ⑤ Date annotation requirements record the date from the test of the function to the end function. 6. There should be a set of special strings used for identification between the function annotation and the function name. If the algorithm is complex or the variable definition in the algorithm is related to the location, the definition of the variable must be illustrated. Explain hard-to-understand algorithms as much as possible. 2. Variable comments: The comment on the variable follows the variable to describe the role of the variable. In principle, each variable should be annotated, but it can be non-Annotated for variable with significant significance, such as I and j. For example, long llinecount // The number of lines. 3. file notes: Add the following comments to the beginning of the file: //////////////////////////////////////// ///////////////////////////// // Project: The project name of the file. // Author: **, modifier :** // Description: describes the functions of the file. // Main function :............ // Version: Specifies the version of the file, and the completion date. // Modify: Describes the file modification content, reasons, and date. // References :...... //////////////////////////////////////// ///////////////////////////// For repeated header file inclusion, the first object must be defined as follows: # Ifndef _ filename_h __ # DEFINE _ filename_h __ Filename indicates the name of the header file. 4. Other notes: In the function, we do not need to comment every line of statements. However, you must add block comments before each major part of each functional module, comment out each group of statements, and comment out as many branches as possible in the loop and process. The cycle, condition, and selection must be commented out. If the order before and after cannot be reversed, we recommend that you add the sequence number in the comment. For example: In other programs executed in sequence, a comment must be added for every 3-5 rows of statements, indicating the role of a small module composed of these statements. Note your own unique ideas in comments. 4. Program Robustness: 1. Specification of function return values: For the return position of a function, try to keep it single, that is, a function tries its best to have only one return position. (Single portal and Single Exit ). It is required that the return values of all functions be unified. The return values of all functions are returned in encoding. For example, the encoding is defined as follows: # Define cm_point_is_null cmmakehr (0x200) : : The recommended function implementation is as follows: Long function name (parameter ,......) { Long lresult; // keep the error code Lresult = cm_ OK; // If the parameter has an error, the error code is returned. If (parameter = NULL) { Lresult = cm_point_is_null; Goto end; } ...... End: Return lresult; } 2. Goto applications: For the application of the GOTO statement, we need to use as few goto statements as possible. Only backward transfer is required. 3. Processing of resource variables (resource variables refer to variables that consume system resources ): Assign an initial value to the resource variable. The allocated resources must be released immediately after they are used up and assigned a value again. 4. To judge complex conditions, brackets should be used whenever possible for program readability. Example: If (szfilename! = NULL) & (lcount> = 0) | (bisreaded = true ))
V. Portability: 1. High quality code requirements can be cross-platform. Therefore, we should consider the support for different platforms, especially for Windows98 and WindowsNT. 2. Due to the good portability of C language, C code is required for Algorithm functions, rather than C ++ code. 3. Perform different processing on functions of different hardware and software. |