Hungarian notation


Hungarian Notation

(language, convention)A linguistic convention requiring oneor more letters to be added to the start of variable namesto denote scope and/or type.

Hungarian Notation is mainly confined to Microsoft Windowsprogramming environments, such as Microsoft C, C++ andVisual Basic. It was originally devised by Charles Simonyi, a Hungarian, who was a senior programmer atMicrosoft for many years. He disliked the way that names inC programs gave no clue as to the type, leading to frequentprogrammer errors.

According to legend, fellow programmers at Microsoft, onseeing the convoluted, vowel-less variable names produced byhis scheme, said, "This might as well be in Greek - or evenHungarian!". They made up the name "Hungarian notation"(possibly with "reverse Polish notation" in mind).

Hungarian Notation is not really necessary when using a modernstrongly-typed language as the compiler warns theprogrammer if a variable of one type is used as if it wereanother type. It is less useful in object-oriented programming languages such as C++, where many variables aregoing to be instances of classes and so begin with "obj".

In addition, variable names are essentially only comments,and thus are just as susceptible to becoming out-of-date andincorrect as any other comment. For example, if a signedshort int becomes an unsigned long int, the variablename, and every use of it, should be changed to reflect itsnew type.

A variable's name should describe the values it holds. Typeand scope are aspects of this, but Hungarian Notationoveremphasises their importance by allocating so much of thestart of the name to them. Furthermore, type and scopeinformation can be found from the variable's declaration.Ironically, this is particularly easy in the developmentenvironments in which Hungarian Notation is typically used.

Simonyi's original monograph.

Microsoft VB Naming Conventions.

Hungarian notation

In programming, the use of standard prefixes in naming variables. For example, "p" means pointer, hence, pTEXTBUF is a pointer to a buffer called TEXTBUF.