Identifier naming rules

Source: Internet
Author: User
Tags uppercase letter

As the name implies, "naming rules" refers to the rules that are followed when the identifier is named.
Identifiers mainly include variable names, function names, class names, and macro names.

Three mainstream nomenclature: Camel (Camel) nomenclature, Pascal (Pascal) nomenclature and Hungarian nomenclature.

Personal habits, general use of camel Nomenclature, the class name object name using Pascal.

database table name uniform all lowercase middle with "_" Separated for example "Cps_user", field names all lowercase can be separated by "_", or not.

Camel's nomenclature has become more and more popular in recent years,
There are many new libraries and Java platforms that are used properly.
The camel nomenclature, as its name implies, refers to the mixture of uppercase and lowercase letters to form the name of an identifier.
One of the first words is lowercase, and the remaining words are capitalized in the first letter.
For example: Printemployeepaychecks (), each logical breakpoint in the function name is marked with an uppercase letter.

Personal feeling advantage is that the identifier is a lot of cases is a word, the people are used to lowercase, capital is a bit awkward after all.


Pascal (Pascal) nomenclature is similar to the Camel name law.
Except that the camel name is the first lowercase letter, and the Pascal nomenclature is the first letter of a word capitalized.
For example: DisplayInfo () and username are all using the Pascal nomenclature.

This kind of nomenclature looks neat, but it is awkward to be capitalized for unification when the identifier has only one word.

First, the Hungarian name law:
Widely used in environments such as Microsoft Windows.

The naming convention for variables (and also macros) used in Windows programming is the Hungarian nomenclature, which is presented by a competent Microsoft programmer Charles Simonyi Charles Simonyi.

The key to Hungarian nomenclature is that the name of the identifier is prefixed with one or more lowercase letters, identifying the scope, type, etc. of the variable. The prefix is followed by a single word or multiple word combinations that are capitalized in the first letter.

For example:

Itotal, Bsort, SName, afield, odate,fncookiecallback the first lowercase characters are labeled with the data type of the identifier.

It is obvious that this method of nomenclature is advantageous in parameter passing.

Prefix type the prefix of the commonly used lowercase letters in Hungarian nomenclature:

A arrays (array)
b Boolean Value (Boolean)
by Byte (byte)
C signed character (Char)
CB unsigned character (Char Byte, not many people used)
CR Color reference value (COLORREF)
Cx,cy coordinate difference (length shortint)
DW Double Word
fn function
H Handle (handle)
I integral type
L Long int
LP Long Pointer
Members of the M_ class
n short integer (shorter int)
NP near Pointer
P Pointer
S-string
SZ null-terminated string type (string with Zero end)
W Word

Identifier naming rules

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.