Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 History  





2 Systems Hungarian vs. Apps Hungarian  





3 Relation to sigils  





4 Examples  





5 Advantages  





6 Disadvantages  





7 Notable opinions  





8 See also  





9 References  





10 External links  














Hungarian notation






Беларуская (тарашкевіца)
Català
Deutsch
Español
فارسی
Français

Italiano
Magyar
Nederlands

Polski
Português
Русский
Српски / srpski
Suomi
Svenska
ி
Українська

 

Edit links
 









Article
Talk
 

















Read
Edit
View history
 








Tools
   


Actions  



Read
Edit
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Cite this page
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 
















Appearance
   

 






From Wikipedia, the free encyclopedia
 

(Redirected from Hungarian Notation)

Hungarian notation is an identifier naming conventionincomputer programming in which the name of a variableorfunction indicates its intention or kind, or in some dialects, its type. The original Hungarian notation uses only intention or kind in its naming convention and is sometimes called Apps Hungarian as it became popular in the Microsoft Apps division in the development of Microsoft Office applications. When the Microsoft Windows division adopted the naming convention, they based it on the actual data type, and this convention became widely spread through the Windows API; this is sometimes called Systems Hungarian notation.

Simonyi: ...BCPL [had] a single type which was a 16-bit word... not that it matters.

Booch: Unless you continue the Hungarian notation.

Simonyi: Absolutely... we went over to the typed languages too later ... But ... we would look at one name and I would tell you exactly a lot about that...[1]

Hungarian notation 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 a group of lower-case letters which are mnemonics for the type or purpose of that variable, followed by whatever name the programmer has chosen; this last part is sometimes distinguished as the given name. The first character of the given name can be capitalized to separate it from the type indicators (see also CamelCase). Otherwise the case of this character denotes scope.

History[edit]

The original Hungarian notation was invented by Charles Simonyi, a programmer who worked at Xerox PARC circa 1972–1981, and who later became Chief Architect at Microsoft. The name of the notation is a reference to Simonyi's nation of origin, and also, according to Andy Hertzfeld, because it made programs "look like they were written in some inscrutable foreign language".[2] Hungarian people's names are "reversed" compared to most other European names; the family name precedes the given name. For example, the anglicized name "Charles Simonyi" in Hungarian was originally "Simonyi Károly". In the same way, the type name precedes the "given name" in Hungarian notation. The similar Smalltalk "type last" naming style (e.g. aPoint and lastPoint) was common at Xerox PARC during Simonyi's tenure there.[citation needed]

Simonyi's paper on the notation referred to prefixes used to indicate the "type" of information being stored.[3][4] His proposal was largely concerned with decorating identifier names based upon the semantic information of what they store (in other words, the variable's purpose). Simonyi's notation came to be called Apps Hungarian, since the convention was used in the applications division of Microsoft. Systems Hungarian developed later in the Microsoft Windows development team. Apps Hungarian is not entirely distinct from what became known as Systems Hungarian, as some of Simonyi's suggested prefixes contain little or no semantic information (see below for examples).[4]

Systems Hungarian vs. Apps Hungarian[edit]

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

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

Apps Hungarian notation strives to encode the logical data type rather than the physical data type; in this way, it gives a hint as to what the variable's purpose is, or what it represents.

Most, but not all, of the prefixes Simonyi suggested are semantic in nature. To modern eyes, some prefixes seem to represent physical data types, such as sz for strings. However, such prefixes were still semantic, as Simonyi intended Hungarian notation for languages whose type systems could not distinguish some data types that modern languages take for granted.

The following are examples from the original paper:[3]

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.

It is possible for code using Apps Hungarian notation to sometimes contain Systems Hungarian when describing variables that are defined solely in terms of their type.

Relation to sigils[edit]

In some programming languages, a similar notation now called sigils is built into the language and enforced by the compiler. For example, in some forms of BASIC, name$ names a string and count% names an integer. The major difference between Hungarian notation and sigils is that sigils declare the type of the variable in the language, whereas Hungarian notation is purely a naming scheme with no effect on the machine interpretation of the program text.

Examples[edit]

The mnemonics for pointers and arrays, which are not actual data types, are usually followed by the type of the data element itself:

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. In particular, use of Hungarian notation was widely evangelizedbyCharles Petzold's "Programming Windows", the original (and for many readers, the definitive) book on Windows API programming. Thus, many commonly seen constructs of Hungarian notation are specific to Windows:

The notation is sometimes extended in C++ to include the scope of a variable, optionally separated by an underscore.[5][6] This extension is often also used without the Hungarian type-specification:

InJavaScript code using jQuery, a $ prefix is often used to indicate that a variable holds a jQuery object (versus a plain DOM object or some other value).[7]

Advantages[edit]

(Some of these apply to Systems Hungarian only.)

Supporters argue that the benefits of Hungarian Notation include:[3]

Disadvantages[edit]

Most arguments against Hungarian notation are against Systems Hungarian notation, not Apps Hungarian notation. Some potential issues are:

Notable opinions[edit]

See also[edit]

References[edit]

  1. ^ "Oral History of Charles Simonyi" (PDF). Archive.computerhistory.org\accessdate=5 August 2018. Archived (PDF) from the original on 2015-09-10.
  • ^ Rosenberg, Scott (1 January 2007). "Anything You Can Do, I Can Do Meta". MIT Technology Review. Retrieved 21 July 2022.
  • ^ a b c Charles Simonyi (November 1999). "Hungarian Notation". MSDN Library. Microsoft Corp.
  • ^ a b c Spolsky, Joel (2005-05-11). "Making Wrong Code Look Wrong". Joel on Software. Retrieved 2005-12-13.
  • ^ "Mozilla Coding Style". Developer.mozilla.org. Archived from the original on 2 December 2019. Retrieved 17 March 2015.
  • ^ "Webkit Coding Style Guidelines". Webkit.org. Retrieved 17 March 2015.
  • ^ "Why would a JavaScript variable start with a dollar sign?". Stack Overflow. Retrieved 12 February 2016.
  • ^ Jones, Derek M. (2009). The New C Standard: A Cultural and Economic Commentary (PDF). Addison-Wesley. p. 727. ISBN 978-0-201-70917-9. Archived (PDF) from the original on 2011-05-01.
  • ^ "Make an app for any task - FileMaker — An Apple Subsidiary". Filemaker.com. Retrieved 5 August 2018.
  • ^ Martin, Robert Cecil (2008). Clean Code: A Handbook of Agile Software Craftsmanship. Redmond, WA: Prentice Hall PTR. ISBN 978-0-13-235088-4.
  • ^ "Linux kernel coding style". Linux kernel documentation. Retrieved 9 March 2018.
  • ^ McConnell, Steve (2004). Code Complete (2nd ed.). Redmond, WA: Microsoft Press. ISBN 0-7356-1967-0.
  • ^ Stroustrup, Bjarne (2007). "Bjarne Stroustrup's C++ Style and Technique FAQ". Retrieved 15 February 2015.
  • ^ "Design Guidelines for Developing Class Libraries: General Naming Conventions". Retrieved 2008-01-03.
  • External links[edit]


    Retrieved from "https://en.wikipedia.org/w/index.php?title=Hungarian_notation&oldid=1227424635"

    Categories: 
    Source code
    Naming conventions
    Hidden categories: 
    Articles with short description
    Short description matches Wikidata
    All articles with unsourced statements
    Articles with unsourced statements from July 2022
    All articles with dead external links
    Articles with dead external links from June 2024
    Articles with permanently dead external links
     



    This page was last edited on 5 June 2024, at 17:01 (UTC).

    Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



    Privacy policy

    About Wikipedia

    Disclaimers

    Contact Wikipedia

    Code of Conduct

    Developers

    Statistics

    Cookie statement

    Mobile view



    Wikimedia Foundation
    Powered by MediaWiki