Hungarian notation
In computer programming, Hungarian notation is a commonly used system for creating variable names. It is also used to name object instances in visual programming languages, such as Delphi. The notation's name comes from the fact that its inventor, Charles Simonyi, was born in Hungary.
This convention is rarely used in older versions of Delphi but is widely used by Microsoft programmers and, in particular, in Windows operating system programming.
Consists of lowercase prefixes added to variable names to indicate their type. The rest of the name indicates, as clearly as possible, the function that the variable performs.
Examples
Prefix | Meaning |
---|---|
b | Booleano (int) |
by | BYTE or UCHAR (unsigned char) |
c | Character (a byte) |
dw | 32-bit long connector with no sign (double word) |
f | Flags packed into a 16-bit integer |
h | 16-bit handler (handle) |
l | 32-bit longint |
lbl | Object Label |
lp | 32-bit long integer |
lpfn | Long point to a function that returns an integer |
lpsz | Long pointer to a string finished with zero |
n | 16-bit entero |
p | 16-bit integer |
e | Enumeration |
pt | Coordinates (x, and) packaged in a 32-bit integer |
rgb | RGB color value packaged in a 32-bit integer |
sz | Chain completed at zero |
txt | Text boxes |
w | 16-bit shortint without sign (word) |
- n Counter: the variable is an integer that will be used as an accountant.
- szName: a string finished with zero which stores a name.
- bAnswer: a boolean variable that stores an answer.
- txtHora: an instance of a textbox object that stores the time.
Current situation
Today there are more detractors than supporters of the Hungarian notation. Most of today's development tools, particularly those for use with statically typed languages, offer simple mechanisms for finding out the type of variables without resorting to looking up their declaration.
1-character notation example
Prefix | Meaning |
---|---|
a | 'array'. For vectors/matrics/lists of n dimensions ordered scale. |
b | 'booleano'. For variables that take only two types of values. |
c | 'car'. For the primitive type of individual alphanumeric character. |
d | 'double'. For high-precision numerical types, such as double or float. |
e | 'event'. For events. |
f | 'function'. We will only use it in front of functions when it comes to functions that are added as observers of an event (since using this notation for any method or function would be quite cumbersome). |
g | 'delegated'. For delegates. |
h | 'hashtable'. Ordinary collections by hash (hUsers[“juan23”]). |
i | 'int'. For integers in general, both normal integers and those integer types of more capacity (like long). |
l | 'lock'. For control objects that facilitate the use of mutual exclusions, locks and traffic lights. |
n | 'enum'. For listed types. |
or | 'object'. For objects in general (the Hungarian notation should not be used to distinguish between types of objects, except few exceptions). |
p | 'puntero'. For language with arithmetic pointers. |
s | 'string'. For text string type variables, whether native or chars arrays. This type of data is very common in language without pointer logic. If the “String” type object is used in these cases, we will go to this identifier instead of the ‘or’ object. |
t | 'struct'. Similar to the 'or' of objects, this would be used for struct-type variables in general (i.e., primitive-type objects). |
v | 'variable'. For variables that acquire different types of values. Normally we will only go to this option in non-typed languages (such as JavaScript/EcmaScript). We will use it when we are not sure of the type of value that will hold a variable. It can also be used for objects with a generic type T. |
and | 'byte'. |
This example of Hungarian notation will not seem as critical and strange as the one given at the beginning of the article, in which up to four letters were used to denote the type.
Contenido relacionado
Forth
ScummVM
Portage (software)