Google
 
   
Login
Username:

Password:


Lost Password?

Register now!
Search
Main Menu
top books
Polls
What do you think about php-deluxe.net?
Excellent!
Cool
Hmm..not bad
What the hell is this?
encyclopedia
recommendation
compare webbrowser
Freenet DSL
Who's Online
6 user(s) are online (5 user(s) are browsing encyclopedia)

Members: 0
Guests: 6

more...
browser tip
Unix Befehle
manual of unix befehle
recommendation!
Sponsored
partner

Hungarian notation

Hungarian notation is a identifier naming convention in computer programming, in which the name of an object (computer science) indicates its data type or intended use. There are two types of Hungarian notation: Systems Hungarian notation and Apps Hungarian notation.

It was designed to be language-independent, and found its first major use with the BCPL programming language. Because BCPL has no data types other than the machine word, nothing in the language itself helps a programmer remember variables types. Hungarian notation aims to remedy this by providing the programmer with explicit knowledge of each variable s data type.

In Hungarian notation, a variable name starts with one or more lower-case letters which are mnemonics for the type or purpose of that variable, followed by whatever the name the programmer has chosen; this last part is sometimes distinguished as the given name. The first character of the given name is capitalized to separate it from the type indicators (see also CamelCase).

= Systems vs. Apps Hungarian =

Where Systems notation and Apps notation differ is in the purpose of the prefixes.

In Systems Hungarian notation, the most common form, the prefix encodes the actual data type of the variable. For example:

  • ulAccountNum : variable is an unsigned long integer
  • szName : variable is a zero-terminated string
  • Apps Hungarian notation doesn t encode the actual data type but rather, it gives a hint as to what the variable s purpose is, or what it represents.

  • rwPosition : variable represents a row
  • usName : variable represents an unsafe string , which needs to be translated by some function to make it safe (e.g. see Cross site scripting)
  • While the notation always uses initial lower-case letters as mnemonics, it does not prescribe the mnemonics themselves. There are several widely used conventions (see examples below), but any set of letters can be used, as long as they are consistent within a given body of code.

    =Similar notations in other programming languages=

    In some programming languages, a similar notation is built into the language. For example, in BASIC programming language, name$ names a string and count% names an integer, while in Fortran, variables beginning with I, J, K, L, M, and N are automatically treated as integers by default. Other computer languages such as Perl deduce type from context, while some like Pascal programming language and Java programming language use static typing to prevent operations involving incompatible types in the first place.

    =Examples=

  • nSize : integer
  • cApples : count of items
  • dwLightYears : double Word_(computer_science)
  • bBusy : Boolean datatype
  • fBusy : Boolean datatype (flag)
  • pFoo : Pointer
  • szLastName : zero-terminated string
  • rgStudents : array, or range
  • The mnemonics for pointers and arrays, which are not actual data types, are usually followed by the type of the data element itself:

  • rgfBalances : array of floating-point values
  • pszOwner : pointer to zero-terminated string
  • While Hungarian notation can be applied to any programming language and environment, it was widely adopted by Microsoft for use with the C language, in particular for Microsoft Windows, and its use remains largely confined to that area. Thus, many commonly-seen constructs of Hungarian notation are specific to Windows:

  • hwndFoo : handle to a window
  • lpszBar : long pointer to a zero-terminated string
  • The notation is sometimes extended in C plus plus to include the scope (programming) of a variable, separated by an underscore:

  • m_nWheels : member of a class, integer
  • Hungarian notation becomes confusing when it is used to represent several properties; this is illustrated in the following example:

  • a_crszkvc30LastNameCol : constant reference (computer science) function (programming) parameter (computer science), holding contents of a Database column of type varchar(30) called LastName that was part of the table s primary key
  • =Origin=

    The original Hungarian notation was Apps Hungarian, which was invented by Charles Simonyi, a programmer working at Xerox, who later became Chief Architect at Microsoft. The name comes from Simonyi s nation of origin, and was also probably inspired by the name of an unrelated concept, Polish notation. The name Apps Hungarian was coined since the convention was used in the application software division of Microsoft.

    Systems Hungarian developed later in the Microsoft Windows development team. Simonyi s paper referred to prefixes used to indicate the type of information being stored; the word type was misunderstood to mean data type , and systems of prefixes started to be devised on the basis of this misunderstanding.

    The term Hungarian notation is memorable for many people because the strings of unpronounceable consonants vaguely resemble the consonant-rich orthography of some Eastern European languages (although Hungarian is not a consonant-rich language!).

    =External links=

    *[http://www.parc.com/about/history/publications/bw-ps-gz/csl76-7.ps.gz Meta-Programming: A Software Production Method]. Charles Simonyi, December 1976 (PhD Thesis123) *[http://msdn.microsoft.com/library/en-us/dnvs600/html/HungaNotat.asp Charles Simonyi s explanation of Hungarian Notation] *[http://blogs.msdn.com/larryosterman/archive/2004/06/22/162629.aspx Apps Hungarian Notation] *[http://msdn.microsoft.com/archive/en-us/dnarw98bk/html/variablenameshungariannotation.asp MSDN Windows 98 Conventions and Data Types] *[http://c2.com/cgi/wikiHungarianNotation Portland Pattern Repository Wiki discussion] *[http://www.joelonsoftware.com/articles/Wrong.html Making Wrong Code Look Wrong] *[http://www.byteshift.de/msg/hungarian-notation-doug-klunder HTML version of Doug Klunder s paper]