Hungarian notation

format_list_bulleted Contenido keyboard_arrow_down
ImprimirCitar

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
bBooleano (int)
byBYTE or UCHAR (unsigned char)
cCharacter (a byte)
dw32-bit long connector with no sign (double word)
fFlags packed into a 16-bit integer
h16-bit handler (handle)
l32-bit longint
lblObject Label
lp32-bit long integer
lpfnLong point to a function that returns an integer
lpszLong pointer to a string finished with zero
n16-bit entero
p16-bit integer
eEnumeration
ptCoordinates (x, and) packaged in a 32-bit integer
rgbRGB color value packaged in a 32-bit integer
szChain completed at zero
txtText boxes
w16-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

Forth or FORTH is a programming language and programming environment for computers devised by Charles H. Moore between 1965 and 1970 at the National Radio...

ScummVM

ScummVM is a computer program that allows you to run graphic adventures originally created for the LucasArts SCUMM engine. ScummVM also supports a variety of...

Portage (software)

Portage is the official package manager for the Linux distribution Gentoo and its derivatives Funtoo, Calculate Linux, as well as Chrome...
Más resultados...
Tamaño del texto:
undoredo
format_boldformat_italicformat_underlinedstrikethrough_ssuperscriptsubscriptlink
save