Summary of naming conventions for C ++, Java, and C)

Source: Internet
Author: User

Summary of naming rules for C ++, Java, and C #
Preface

Since C ++, Java, and C # are often used as development languages in development work, naming conventions often cause some problems to me. On the one hand, naming conventions do not have the only standard answer. On the other hand, although there is no fixed form of naming conventions for languages, the three languages have different styles and have their own unique characteristics. CompileCodeThe naming method used in the process is often changed, and there is no fixed style. Therefore, based on some information collected from the Internet and some of its own experience, the naming conventions of C ++, Java, and C # are summarized to facilitate future queries.

Naming rules:

L use naming rules as far as possible;

L try to adopt the same naming rules in three languages to facilitate memory;

L use naming rules from the official authorities (such as Sun and Ms) whenever possible.

 
1. Hungarian, camel, and Pascal

The Hungarian naming method is widely used in Windows programming.ProgramPersonnel proposed. The Hungarian naming method identifies the scope and type of the variable by adding the symbol of the corresponding lowercase letter before the variable name as the prefix. For example, m_lpszstr indicates a long pointer member variable pointing to a string ending with 0 characters. In object-oriented programming, the Hungarian naming method is very awkward to use.

Camel naming method: the camel naming method, because the name using this naming method looks like a camel's camel. The camel naming method has two forms: the combination of uppercase and lowercase letters and words is underlined. For example, runfast and run_fast both belong to the camel naming method.

The Pascal naming method is similar to the camel naming method, but the first letter of the Pascal naming method is an upper-case letter.

 
2. Naming Conventions
Identifier type
C ++
Java
C #

File Name
Similar to the class name, the definition class is usually a pair of file names, such as foobar. h and foobar. cpp.
Same as the class name.
Same as Java.

Namespace, package
Same as C #.
The prefix of the package name is all lowercase asii characters and is a top-level domain name, usually COM, Edu, Gov, net, org. The subsequent parts of the package name vary according to the naming rules of different organizations. Such naming rules may distinguish departments, projects, machines, or registration names based on specific directory names.

Example:

L com. Sun. Eng

L com. Apple. Quicktime. v2

L edu. CMU. cs. bovik. Cheese
Pascal naming method, which starts with a name with a large range.

Example:

L oracle. Data. access;

L Microsoft. Office. Excel;

Enumerated Value
Pascal naming method. The Enumeration type names are added before the enumerated values and separated by an underscore.

Example:

L Enum color {color_red, color_green };
Pascal naming method.

Example:

L Enum color {red, green };
Same as Java.

Class, struct, type definition (typedef), enumeration type
Same as Java.
Pascal naming method.

Example:

L class raster;

L class imagesprite;
Same as Java.

Interface
Same as the type naming convention.
Naming rules are similar to class names.

Example:

L Interface rasterdelegate;

L Interface storing;
The name of Pascal, which must be prefixed with the character "I ".

Example:

L Interface itester;

L Interface ilogger;

Method
Same as C #.
Camel naming method.

Example:

L run ();

L runfast ();

L getbackground ();
Pascal naming method.

Example:

L run ();

L runfast ();

L getbackground ();

Variables and parameters in the Method
Same as Java.
Camel naming method.

Example:

L int mywidth;

L int taxtotal;
Same as Java.

Private and protected instance fields
Same as Java.
Camel naming method, which must be prefixed with an underscore "_".

Example:

L int _ employeeid;

L string _ name;

L customer _ customer;
Same as Java.

Attributes and access functions
Add "get" to the front of the READ function, and add "set" to the front of the Set function ".

Example:

L getemployeeid ();

L setname ();

L getcustomer ();
Add "get" to the front of the READ function, and add "set" to the front of the Set function ".

Example:

L getemployeeid ();

L setname ();

L getcustomer ();
Same as the method naming rule, it should be the same as the field name. We recommend that you use automatic attributes.

Example:

 

Constant
Same as Java.
All uppercase letters are separated by underscores.

Example:

L static final int min_width = 4;

L static final int max_width = 999;

L static final int get_the_cpu = 1;
Same as Java.

Event
None
None
Pascal naming method.

Example:

L formclosing;

L valuechanged;

L buttonclicked;

Exception type
Inherited from STD: exception. It is the same as the type naming rule and ends with exception.
It is inherited from Java. Lang. exception, which is the same as the type naming rule and ends with exception.
It is inherited from system. exception. It is the same as the type naming rule and ends with exception.

 
References

Google C ++ programming style guide: http://www.cppblog.com/Fox/category/6273.html? Show = all

Java coding specification: http://huihoo.org/code/java_code_conventions.html

. NET Framework developer guide-naming rules: http://msdn.microsoft.com/zh-cn/library/ms229002 (vs.80). aspx

C # naming rules, development habits and style: http://www.cnblogs.com/netshuai/archive/2008/06/29/1231934.html

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.