Generated by DeepSeek V3.2Hungarian notation is a naming convention in computer programming where the name of a variable or function indicates its data type or intended use. It was widely promoted within Microsoft during the 1980s and 1990s, becoming particularly associated with the Windows API and early C programming. The practice aimed to make code more readable and reduce errors by embedding semantic hints directly into identifier names, though its application and utility became a subject of significant debate.
The convention's name is a reference to the ethnicity of its original proponent, Charles Simonyi, a Hungarian programmer who worked at the Xerox PARC research center before joining Microsoft. Simonyi introduced the idea in his 1979 doctoral dissertation from Stanford University, titled "Meta-Programming: A Software Production Method." The notation was systematically adopted for the development of Microsoft Word and Microsoft Excel, and its use was cemented through influential texts like Charles Petzold's "Programming Windows." The internal programming standards at Microsoft, especially for the Windows 3.1 and Windows 95 eras, mandated its use, spreading it throughout the ecosystem of third-party Windows developers.
The core syntax involves prefixing a variable name with a lowercase tag that encodes type information. For instance, in the Windows API, `lpszFileName` breaks down to a **l**ong pointer (`lp`) to a **s**tring terminated by a **z**ero (`sz`). Other common prefixes included `dw` for DWORD (double word), `h` for a handle (as in `hWnd` for a window handle), and `b` for a BOOL. A function like `GetWindowText(hWnd, lpszString, nMaxCount)` demonstrates its typical use within the Win32 subsystem. This explicit tagging was intended to prevent type mismatches, such as accidentally assigning a WORD to a DWORD, which were common in the weakly-typed C environment of early Windows NT.
Two main variants emerged: **Systems Hungarian** and **Apps Hungarian**, a distinction later clarified by Joel Spolsky. Systems Hungarian, the more common and widely criticized form, strictly encodes the physical data type (like `i` for integer or `str` for string). This became pervasive in MFC and Visual Basic. Apps Hungarian, which Simonyi originally advocated, prefixes indicate the logical *kind* of data or its *semantic role*, such as `us` for unsafe string or `rw` for row coordinate. This variant was used in complex applications like Microsoft Excel to distinguish between different coordinate systems. Conventions also differed between organizations; while Microsoft heavily used it, other entities like the GNU Project generally avoided it in favor of styles described in works like "The C Programming Language" by Brian Kernighan and Dennis Ritchie.
The convention faced substantial criticism from prominent figures in computer science. Linus Torvalds famously derided it in the context of Linux kernel development, and Robert C. Martin cited it as an unnecessary redundancy in "Clean Code: A Handbook of Agile Software Craftsmanship." The rise of modern IDEs with features like IntelliSense and code completion made manually encoded type information obsolete. Furthermore, the advent of stronger type systems in languages like Java, C#, and Swift rendered the practice largely superfluous. The shift towards agile software development and test-driven development also emphasized different code clarity techniques, leading to its decline outside of maintaining legacy systems like older Windows CE projects.
Despite its fall from favor, Hungarian notation left a lasting imprint on software engineering. It influenced later naming conventions, such as the use of `m_` for member variables in C++ and the Pascal case naming within the .NET Framework. Its philosophy of embedding meaning into names persists in concepts like domain-driven design and in conventions for HTML and CSS (e.g., `js-` prefixes). The debate it sparked about code readability and maintainability contributed to broader discussions on design patterns and coding conventions. Traces of its syntax can still be seen in parts of the Windows API and within the source code of major projects like the Apache HTTP Server, serving as a historical artifact of a pivotal era in personal computing.
Category:Programming constructs Category:Microsoft development tools Category:Software engineering terminology