FACTOID # 171: In 1900, 22 countries had a higher GDP per capita than Mexico. Current GDP per capita figures show that 79 countries are higher.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

SEARCH ALL

FACTS & STATISTICS    Advanced view

Search encyclopedia, statistics and forums:

 

 

(* = Graphable)

 

 


Encyclopedia > Hungarian notation

Updated 347 days 14 hours 1 minutes ago.

Hungarian notation is a naming convention in computer programming, in which the name of a variable indicates its type or intended use. There are two types of Hungarian notation: Systems Hungarian notation and Apps Hungarian notation. In computer programming a naming convention is a set of rules for choosing identifiers. ... Computer programming (often shortened to programming or coding) is the process of writing, testing, and maintaining the source code of computer programs. ... In computer science and mathematics, a variable is a symbol denoting a quantity or symbolic representation. ... A data type is a constraint placed upon the interpretation of data in a type system in computer programming. ...


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. BCPL (Basic Combined Programming Language) is a computer programming language that was designed by Martin Richards of the University of Cambridge in 1966; it was originally intended for use in writing compilers for other languages. ...


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 can be capitalised to separate it from the type indicators (see also CamelCase). Otherwise the case of this character denotes scope. Wikiquote has a collection of quotations related to: English mnemonics A mnemonic (pronounced in RP, [nɪmɑnɪk] in GA) is a memory aid, and most serve an educational purpose. ... This article does not cite any references or sources. ...

Contents

[edit] History

The original Hungarian notation, which would now be called Apps Hungarian, was invented by Charles Simonyi, a programmer who worked at Xerox PARC circa 1972-1981, and who later became Chief Architect at Microsoft. Charles Simonyi (Hungarian: Simonyi Károly; born September 10, 1948, Budapest) is a computer software executive who, as head of Microsofts application software group, oversaw the creation of Microsofts flagship office applications. ... Bold text // Headline text Link title This article is about the computer research center. ... 1972 (MCMLXXII) was a leap year starting on Saturday. ... 1981 (MCMLXXXI) was a common year starting on Thursday of the Gregorian calendar. ... Microsoft Corporation, (NASDAQ: MSFT, HKSE: 4338) is a multinational computer technology corporation with global annual revenue of US$44. ...


The notation is named for Simonyi's nation of origin. 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 rather than the more natural, to most Europeans, Smalltalk "type last" naming style e.g. aPoint and lastPoint. This latter naming style was most common at Xerox PARC during Simonyi's tenure there. It may also be inspired by play on the name of an unrelated concept, Polish notation. // Orthography Modern Hungarian orthography is slightly different (simpler) than that of 18th or 19th century, but many Hungarian surnames retain their historical spelling. ... For other uses, see Small Talk (disambiguation). ... It has been suggested that this article or section be merged with Reverse Polish notation. ...


The name Apps Hungarian was coined since the convention was used in the applications 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. 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), consistent with Apps Hungarian. However, his suggestions were not entirely distinct from what became known as Systems Hungarian, as some of his suggested prefixes contain little or no semantic information. (See below for examples.) This article or section does not cite any references or sources. ... Microsoft Windows is the name of several families of proprietary software operating systems by Microsoft. ...


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 despite the fact that Hungarian is a Finno-Ugric, not a Slavic, language, and so is rather richer in vowels. For example the zero-terminated string prefix "sz" is also a letter in the Hungarian alphabet (think the Eszett 'ß' from German). Map of Eastern Europe Pre-1989 division between the West (grey) and Eastern Bloc (orange) superimposed on current national boundaries: Russia (dark orange), other countries of the former USSR (medium orange),members of the Warsaw pact (light orange), and other former Communist regimes not aligned with Moscow (lightest orange). ... Geographical distribution of Finno-Ugric (Finno-Permic in blue, Ugric in green). ... The Slavic languages (also called Slavonic languages) comprise the languages of the Slavic peoples. ... Linguistics & Pronunciation Sz is the thirty-second letter of the Hungarian alphabet. ... The Hungarian alphabet is an extension of the Roman alphabet. ... The ß — Eszett [] in German or scharfes Es (sharp es) if spelled out — is a letter used only in the German alphabet. ...


[edit] 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 ("ul");
  • szName : variable is a zero-terminated string ("sz"); this was one of Simonyi's original suggested prefixes.

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 ("rw");
  • usName : variable represents an unsafe string ("us"), which needs to be "sanitized" before it is used (e.g. see code injection and cross-site scripting for examples of attacks that can be caused by using raw user input)
  • strName : Variable represents a string ("str") containing the name, but does not specify how that string is implemented.

While most of the prefixes Simonyi suggested are semantic in nature, not all are. The following are examples from the original paper: [1] To meet Wikipedias quality standards, this article or section may require cleanup. ... Cross-site scripting (XSS) is a type of computer security vulnerability typically found in web applications which allow code injection by malicious web users into the web pages viewed by other users. ...

  • pX is a pointer to another type X; this contains very little semantic information.
  • d is a prefix meaning difference between two values; for instance, dY might represent a distance along the Y-axis of a graph, while a variable just called y might be an absolute position. This is entirely semantic in nature.
  • sz is a null- or zero-terminated string. In C, this contains some semantic information because it's not clear whether a variable of type char* is a pointer to a single character or an entire string.
  • w marks a variable that is a word. This contains essentially no semantic information at all, and would probably be considered Systems Hungarian.
  • b marks a byte, which in contrast to w might have semantic information, because in C the only byte-sized data type is the char, so these are sometimes used to hold numeric values. This prefix might clear ambiguity between whether the variable is holding a value that should be treated as a letter (or more generally a character) or a number.

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.


[edit] Relation to sigils

In some programming languages, a similar notation now called sigils is built into the language and enforced by the compiler. For example, in BASIC, name$ names a string and count% names an integer, and in Perl, $name refers to a scalar value while @namelist refers to a list of values. Sigils have the notable advantages over Hungarian notation that they implicitly define the type of the variable without need for redundant declaration, and are also checked by the compiler, preventing omission and misuse. In computer programming, a sigil is a symbol attached to a variable name, showing the variables datatype. ... BASIC (Beginners All-purpose Symbolic Instruction Code) is a family of high-level programming languages. ... In computer programming and formal language theory, (and other branches of mathematics), a string is an ordered sequence of symbols. ... The integers are commonly denoted by the above symbol. ... Perl is a dynamic programming language created by Larry Wall and first released in 1987. ...


On the other hand, such systems are in practice less flexible than Hungarian notation, typically defining only a few different types — the lack of an adequate number of different easy-to-remember symbols obstructs more extensive use. In addition, although it has not been done, it is feasible to construct a static-checking tool which could statically verify the presence and correctness of Hungarian prefixes.


[edit] Examples

  • bBusy : boolean
  • cApples : count of items
  • dwLightYears : double word (systems)
  • fBusy : boolean (flag)
  • nSize : integer (systems) or count (application)
  • iSize : integer (systems) or index (application)
  • fpPrice: floating-point
  • dbPi : double (systems)
  • pFoo : pointer
  • rgStudents : array, or range
  • szLastName : zero-terminated string
  • u32Identifier : unsigned 32-bit integer (systems)
  • stTime : clock time structure
  • fnFunction : function name

The mnemonics for pointers and arrays, which are not actual data types, are usually followed by the type of the data element itself: In computer science, the Boolean datatype, sometimes called the logical datatype, is a primitive datatype having two values: one and zero (which are equivalent to true and false). ... In computing, word is a term for the natural unit of data used by a particular computer design. ... In computer science, the Boolean datatype, sometimes called the logical datatype, is a primitive datatype having two values: one and zero (which are equivalent to true and false). ... In computer science, the term integer is used to refer to any data type which can represent some subset of the mathematical integers. ... In computer science, the term integer is used to refer to any data type which can represent some subset of the mathematical integers. ... This article or section is in need of attention from an expert on the subject. ... In computing, double precision is a computer numbering format that occupies two storage locations in computer memory at address and address+1. ... It has been suggested that Software pointer be merged into this article or section. ... In computer science, the term integer is used to refer to any data type which can represent some subset of the mathematical integers. ... This article or section does not cite its references or sources. ...

  • pszOwner : pointer to zero-terminated string
  • rgfpBalances : array of floating-point values

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: This article or section is in need of attention from an expert on the subject. ... Microsoft Corporation, (NASDAQ: MSFT, HKSE: 4338) is a multinational computer technology corporation with global annual revenue of US$44. ... Microsoft Windows is the name of several families of proprietary software operating systems by Microsoft. ...

  • hwndFoo : handle to a window
  • lpszBar : long pointer to a zero-terminated string

The notation is sometimes extended in C++ to include the scope of a variable, separated by an underscore: C++ (pronounced see plus plus, IPA: ) is a general-purpose, high-level programming language with low-level facilities. ... In computer programming in general, a scope is an enclosing context. ...

  • g_nWheels : member of a global namespace, integer
  • m_nWheels : member of a structure/class, integer

[edit] Controversy

(These mainly apply to Systems Hungarian only.) Supporters argue that the benefits include:[1]

  • The variable type can be seen from its name
  • Variable names can be easy to remember from knowing just their types.
  • It leads to more consistent variable names
  • Deciding on a variable name can be a mechanical, and thus quick, process
  • Inappropriate type casting and operations using incompatible types can be detected easily
  • Useful with string based languages where numerics are strings (Tcl for example)
  • In Apps Hungarian, the variable name guards against using it in an improper operation with the same data type by making the error obvious as in:
heightWindow = window.getWidth()

Whilst critics argue that: Tcl (originally from Tool Command Language, but nonetheless conventionally rendered as Tcl rather than TCL; and pronounced tickle) is a scripting language created by John Ousterhout. ...

  • The Hungarian notation is redundant with the type checking made by the compiler. A language providing the slightest type verification will be much more powerful to assert that the usage of a variable is consistent with its type, than the human eye would be to barely check that this usage is coherent with the name of the variable.
  • Modern Integrated development environments display variable types on demand, and automatically flag operations which use incompatible types, making the notation obsolete.
  • It becomes confusing when it is used to represent several properties, as in: ::a_crszkvc30LastNameCol : constant reference function argument, holding contents of a database column of type varchar(30) called LastName that was part of the table's primary key
  • It may lead to inconsistency when code is modified. If a variable's type is changed, its name may reflect the previous type, leading to confusion.
  • It is inconsistent with code portability since the variable name is tied to the type. A particularly well known example is the standard WPARAM type, and the accompanying wParam formal parameter in many Windows system function declarations. It was originally a 16 bit type, but was changed to a 32 bit or 64 bit type in later versions of the operating system while retaining its original name (its true underlying type is UINT_PTR, that is, an unsigned integer large enough to hold a pointer).

The .NET Framework, Microsoft's new software development platform, lacks Hungarian notation completely; the .NET Framework Guidelines advise programmers that it should not be used. [2] This article or section does not cite any references or sources. ... In mathematics and the mathematical sciences, a constant is a fixed, but possibly unspecified, value. ... This article discusses a general notion of reference in computing. ... In computer science, a subroutine (function, procedure, or subprogram) is a sequence of code which performs a specific task, as part of a larger program, and is grouped as one, or more, statement blocks; such code is sometimes collected into software libraries. ... A parameter is a variable which can be accepted by a subroutine. ... In computing , a database can be defined as a structured collection of records or data that is stored in a computer so that a program can consult it to answer queries. ... A Variable Character Field (or varchar) is a set of character data of indeterminate length. ... In database design, a primary key is a value that can be used to identify a unique row in a table. ... A parameter is a measurement or value on which something else depends. ... The Microsoft . ...


[edit] Notes and references

  1. ^ a b "Hungarian Notation" (defined), Charles Simonyi, Microsoft Corp., November 1999, MSDN Library, MSDN.microsoft.com webpage: Hungarian Notation, Charles Simonyi, Microsoft Corporation.
  2. ^ .NET Framework Developer's Guide General Naming Conventions

Charles Simonyi (Hungarian: Simonyi Károly; born September 10, 1948, Budapest) is a computer software executive who, as head of Microsofts application software group, oversaw the creation of Microsofts flagship office applications. ... Microsoft Corporation, (NASDAQ: MSFT, HKSE: 4338) is a multinational computer technology corporation with global annual revenue of US$44. ... Year 1999 (MCMXCIX) was a common year starting on Friday (link will display full 1999 Gregorian calendar). ...

[edit] External links


  Results from FactBites:
 
(ootips) Hungarian Notation - The Good, The Bad and The Ugly (671 words)
The advantage of Hungarian notation is a reminder of the type of a variable.
Hungarian notation (or a variation of this) has its place in C++ when referring to data that really DOES have a particular type, by its very nature.
Hungarian notation is, when all is said and done, a commenting technique.
Hungarian notation - Wikipedia, the free encyclopedia (1021 words)
Hungarian notation is a naming convention in computer programming, in which the name of an object indicates its type or intended use.
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.
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.
  More results at FactBites »

 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your location
Your comments
Please enter the 5-letter protection code


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms.