Huawei software programming specification Learning (3)-identifier naming

Source: Internet
Author: User

Huawei software programming standard learning (3) -- identifier naming

3-1: The name of the identifier must be clear, clear, and meaningful. The complete words or abbreviations can be used to avoid misunderstanding.

Note:Short words can be abbreviated by removing the "vowel"; long words can be abbreviated by the first few letters of a word; some words are accepted as abbreviations.

Example: The abbreviations of the following words can be basically recognized by everyone.

Temp can be abbreviated to TMP;

Flag can be abbreviated as flg;

Statistic can be abbreviated as Stat;

Increment can be abbreviated as Inc;

Message can be abbreviated to MSG;

3-2: If special conventions or abbreviations are used in naming, a comment should be provided.

Note: The abbreviations or conventions used in the file, especially special abbreviations, should be annotated at the beginning of the source file.

3-3: your own naming style,It must be consistent from start to end and cannot be changed back and forth

Note: an individual's naming style can be used only when it complies with the naming rules of the project team or product group. (That is, the personal naming style is available only in areas not specified in the naming rules.).

3-4: for variable naming, it is not allowed to take a single character (such as I, J, K ...), in addition to specific meanings, we recommend that you also specify the variable type and data type. However, I, J, and K are allowed for local cyclic variables.

Note: variables, especially local variables, are represented by a single character and can be easily typed incorrectly (for example, I is written as J), but cannot be checked during compilation, it may take a lot of time to identify this small error.

Example: The following describes how to define a local variable name.

Int liv_width

The variable name is described as follows:

L local (Other: G global variable (global )...)

I Data Type (interger)

V variable (variable) (OTHERS: C constant (const )...)

Description of the width variable

This prevents duplicate names of local variables and global variables.

3-5: The naming rules must be consistent with the system style used, and should be consistent in the same project. For example, the UNIX style should be in lower case or mixed case, do not use case-and-underline-mixed sorting. m_and g _ are used as special identifiers, such as member variables or global variables.

Example: add_user is not allowed. add_user, adduser, and m_adduser are allowed.

Others

3-1: Do not use numbers or strange characters to define identifiers unless necessary

Example: The following naming is confusing.

# DEFINE _ example_0_test _

# DEFINE _ example_1_test _

Void set_sls00 (bytesls );

Should be changed to meaningful word names

# DEFINE _ example_unit_test _

# DEFINE _ example_assert_test _

Void set_udt_msg_sls (byte SLS );

3-2: In the same software product, the names of some identifiers (variables, structures, functions, and constants) of interfaces should be planned to prevent conflicts during compilation and linking.

Note: There should be stricter restrictions on interface identifiers to prevent conflicts. For example, you can add the "module" identifier before the variables and constants in the interface section.

3-3: Use a correct antgroup to name variables with mutex meanings or functions with opposite actions

Note: The following are some antgroups that are commonly used in software.

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 min_sum;

Int max_sum;

Int add_user (byte * user_name );

Int delete_user (byte * user_name );

3-4: In addition to compiling the switch/header file and other special applications, avoid using _ example_test _ or the following dashes to start and end the definition.

Related Article

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.