Hungarian naming norm
A few years ago, Charles Simonyi (he became a famous programmer of Microsoft), designed a prefix-based naming method, which later called "Hungarian Expression" to remember him. His thought is based on each The meaning representative of the identifier gives it a prefix. Microsoft later used this idea to give each identifier a prefix to explain its data type. Therefore, the prefix of the integer variable is n, long integer variables are NL, characters Type array variables are CAs, and strings (array ends with empty types) are prefixed in SZ. These names may be very quirky. For example: lpszfoo means "foo" is a string that points to empty characters Long integer pointer.
The advantage of this approach is that people can identify variables through the name of the variable, not to find its definition. Unfortunately, this method not only makes the variable name very winding, but also changes the change of variable types It is very difficult. In Windows3.1, the integer variable is 16 is wide. If we use a integer variable at the beginning, after the calculation of 30 --- 40 functions, it is found to use integer variable width. Not enough, then we must not only change the type of variable, but also to change this variable in this 30-40 function name.
Because unreal, there is no one in addition to some stubborn Windows programmers, there is no doubt. There is no doubt that it still exists in some cases, but most people have already abandoned it. Generally speaking The input prefix is a bad idea because it is tightly tightened with the variables.
For a function of 30 lines, Hungarian methods are generally advantageous.
Especially for interface programming, it has an advantage.
But for a strong algorithm requirement, especially if there are many abstract type C programs, Hungarian methods are simply a disaster.
See where you are using.
Now there is a good IDE tool, such as: VC, SourceInsight, etc.
Select variables, will automatically prompt you to declare and definition, so
The Hungarian nomenclature is not very necessary.
It is nothing more than the program readability.
In fact, good code writing habits are more important than force to use Hungarian nomenclature.
Systemic. Integrity. readability. Category is clear. To have a comment!
The Hungarian nomenclature is a naming specification for a variable, function, object, prefix, macro definition, and other types of symbols. The main idea of Hungarian nomenclature is: adding prefix in variables and function names to enhance people's understanding of procedures. It is used by a Hungarian in Microsoft, and it is gradually popular in Microsoft, and promotes Windows developers around the world. Here will be introduced to the Hungarian nomenclature, and the following example will try to comply with it and the above code style. Or that sentence is not asking all readers to follow, but I hope the reader will follow it as a modern software developer.
A array array
B Bool (int) Boolean (integer)
By unsigned char (byte) No symbolic characters (bytes)
C char character (byte)
CB Count of bytes bytes
Cr Color Reference Value Color (Reference) Value
CX Count of X (Short) X Collection (Short Integer)
DW DWORD (unsigned long) double word (no symbol length)
f Flags (USUALLY MULTIPLE BIT VALUES) Sign (generally multiple values)
Fn function function
G_ Global Global
H handle handle i integer integer
l Long long integer
LP Long Pointer long pointer
M_ Data Member of a Class A class of data members
N Short Int short integer
P P Pointer pointer
String string
SZ ZERO TERMINATED STRING string ends with 0
TM Text Metric Text Rules
u Unsigned int unsigned integer
UL unsigned long (ulong) unsigned long integer
W Word (unsigned short) no symbol short integer
X, Y X, Y Coordinates (Short) Coordinate Value / Short Integer
v void empty
The global variable of the project is started with G_, the class member variables use m_, and the local variables are larger, and L_ can be considered to display them to show a local variable.
Prefix type example
G_ global variable g_servers
Class C or struct cDocument, CPrintinfo
M_ member variable m_pdoc, m_ncustomers
VC common prefix list:
Prefix type description example
CH char 8-bit character chgrade
CH Tchar 16 Unicode Type Characters Chname
B Bool Boolean Variable Benabled
n int integer (whose size is determined by operating system) NLENGTH
N uint No symbol integer (its size is determined by operating system) NLENGTH
W word 16-bit unsigned integer WPOS
l Long 32 with symbolic Loffset
DW DWORD 32-bit unsigned integer DWRANGE
P * Ambient Memory Model Pointer Memory Module Pointer, Pointer Variable PDOC
LP FAR * long pointer LPDOC
LPSZ LPSTR 32-bit string pointer lpszname
LPSZ LPCSTR 32-bit constant string pointer lpszname
LPSZ LPCTSTR 32-bit Unicode Type constant pointer lpszname
H H Handle Windows Object Handle HWND
LPFN (* fn) () callback function pointer Callback Far Pointer to Callback Function LPFNABORTWINDOWS object name abbreviation:
Windows object example variable MFC class example object
HWND HWND; CWND * PWND;
HDLG HDLG; CDIALOG * PDLG;
HDC HDC; CDC * PDC;
HgDiobj hgdiobj; cgdiobject * pgdiobj;
HPEN HPEN; CPEN * PPEN;
Hbrush Hbrush; CBRUSH * PBRUSH;
HFONT HFONT; CFONT * PFONT;
Hbitmap hbitmap; cbitmap * pbitmap;
HPALETTE HPALETTE; CPALETTE * PPALETTE;
HRGN HRGN; CRGN * PRGN;
HMENU HMENU; cmenu * pmenu;
HWND HCTL; CSTATIC * PSTATIC;
HWND HCTL; CBUTTON * PBTN;
HWND HCTL; CEDIT * PEDIT;
HWND HCTL; Clistbox * PListbox;
HWND HCTL; CCOMBOBOX * PCOMBOBOX;