Development specifications and naming rules

Source: Internet
Author: User

_ Cannot be used as the file name in common variables.

1. Class: rclassname starts with the first letter of the r company name,

2. function interface: Use uppercase letters to distinguish between funnames.

3. Common variable: the first letter of agevalue is lowercase.

4. pointer variable: * pstu starts with P

5. global variable: g_howmanypeople starts with G _

6. static variable: s_init

7. replace a constant with c_max c_pi C.

8. Data Member: Members of the m_width m_height class start with M _

9. Enumeration constant: enum_day starts with Enum _: typedef Enum day {Monday, Tuesday} enum_day;
 
1. struct: struct_point starting with sturct _: typedef struct mappoint {} struct_point;

2. Consortium: union_point starts with union _: typedef Union mappoint {} union_point;

3. macro definition: # define d_pi 3.14 starts with "D" and all uppercase letters.

4. Try to use antgroups:
Add/Remove begin/end create/destroy
Insert/Delete first/last get/release
Increment/decrement put/get
Add/delete lock/unlock open/close
Min/MAX old/new start/stop
Next/previous source/Target show/hide
Send/receive source/destination
Cut/paste up/down
Example:
Int minsum;
Int maxsum;
Int adduser (byte * pusername );
Int deleteuser (byte * pusername );

5. {to exclusive a row, even if a statement is used, write {}; Note the indentation, as shown in the case below:
If/For/while
{
Case 0:
//
Break;
Case 1:
//
Break;
}

Comments must be added between 6.2 independent program blocks:
For example, the variable definition area and the condition judgment loop processing area should be separated by blank lines, and the comments should be separated by spaces.

7. long statement expressions should fold rows: each line is broken, and the first letter should be symbols +-these are relatively unified.
Example:
Permcountmsg. Head. Len = no7_to_stat_perm_count_len
+ Stat_size_per_fram * sizeof (_ UL );

Acttasktable [frameid * stat_task_check_number + Index]. Occupied
= Statpoi [Index]. occupied;

Reportornotflag = (taskno <max_act_task_number)
& (N7statitemvalid (stat_item ))
& (Acttasktable [taskno]. resultdata! = 0 ));

8. One statement in a row.

9. Add a space:
1. The variable is defined in, followed by a space: int A, B, C;
2. Add a space between the left and right sides of the binary operator: A = B + C; A * = 2;
3. You do not need a single object: * P = 'a'; P = & men; I ++; A. B a-> B;
4. If for while siwtch (A> = B) & (c> D), it is best to have spaces.

1. Annotations for header files are required:
Rule: Descriptive files (such as header files. h file ,. inc file ,. def file, compilation instructions file. CFG, etc.) the header should be annotated, and the notes must be listed: Copyright description, version number, generation date, author, content, functions, relationships with other files, modification logs, etc, the comment on the header file should also provide a brief description of function functions.

Example: The header comments in the following header file are standard. Of course, they are not limited to this format, but we recommend that you include the above information.
/*************************************** **********
Copyright (C), 2002-2003, Kingdom tech. co., Ltd.
File Name: // file name
Author: Version: Date: // author, version, and completion date
Module: // Module
Description: // describes in detail the main functions of this program file, and other modules.
// Or function interface, control between output values, value ranges, meanings, and parameters
// Relations such as system, order, independence, or dependency
Others: // other content description
Function list: // a list of major functions. Each record should contain a brief description of the function name and function.
1 .....
History: // modify the history list. Each modification record should include the modification date and Modification
// Brief description of the user and the modification content
1. Date:
Author:
Modification:
2 ....
**************************************** *********/

2. source file comment
Rule: The Source File Header must be annotated to list: Copyright description, version number, generation date, author, module purpose/function, main functions and functions, modification log, etc.

Example: The header comments of the following source file are standard. Of course, they are not limited to this format, but we recommend that you include the above information.
/*************************************** *********************
Copyright (C), 2001-2003, Kingdom tech. co., Ltd.
Filename: Test. cpp
Author: Version: Date:
Module: // Module
Description: // description
Version: // version information
Function list: // main functions and functions
1 .-------
History: // history modification record
<Author> <time> <version> <DESC>
David 96/10/12 1.0 Build this Moudle
**************************************** *******************/
Description: describes the content and functions of this file, the relationship between the internal parts, and the relationship between this file and other files. History is a list of modification history records. Each modification record should include the modification date, modifier, and brief description of the modification content.

3.
The function header must be annotated.
Rule: comments should be made to the function header to list: function purpose/function, input parameter, output parameter, return value, call relation (function, table), etc.

Example: The comments of the following function are standard. Of course, they are not limited to this format, but we recommend that you include the above information.
/*************************************** **********
Function: // function name
Description: // description of function functions and performance
Algorithm: // algorithm, main idea
Params:
Param1:
// Description of parameter 1
Param2:
// Description of parameter 2
...
Return: // description of the function return value
**************************************** *********/

4. We recommend that you use the full name if the abbreviated variables and comments are confusing.
5. The general comment should be at: Top, right; try to use:/**/. The comment should be in Chinese.
6. The number of function modules is less than 200. Otherwise, I will score points again.
7. A maximum of five function parameters can be entered.
8. Class Definition: public: protected: Private: sequential write. The class members should use the initialization list whenever possible.
9. Try to use meaningful identifiers instead of numbers: 0: Zero 1: Yes
1. Closely related codes should be adjacent as much as possible: for example:
A. m_height = 10;
P = 3;
A. m_widht = 10 ;=> close: height and width up and down. Enhanced readability.
2. Do not force some obscure "very skillful" statements to use () as much as possible to enhance program readability.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.