Hungarian Notation - Advantages

Advantages

(Some of these apply to Systems Hungarian only.)

Supporters argue that the benefits of Hungarian Notation include:

  • The variable type can be seen from its name. (This is particularly useful when looking at the code outside an integrated development environment - like on a printout).
  • The type of value returned by a function is determined without lookup (i.e. searching for function definitions in other files, e.g. ".h" header files, etc.)
  • The formatting of variable names may simplify some aspects of code refactoring (while making some aspects more error-prone).
  • Multiple variables with similar semantics can be used in a block of code: dwWidth, iWidth, fWidth, dWidth
  • Variable names can be easy to remember from knowing just their types.
  • It leads to more consistent variable names
  • Inappropriate type casting and operations using incompatible types can be detected easily while reading code
  • 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
  • When programming in a language that uses dynamic typing or that is completely untyped, the decorations that refer to types cease to be redundant. Such languages typically do not include declarations of types (or make them optional), so the only sources of what types are allowed are the names themselves, documentation such as comments, and by reading the code to understand what it does. In these languages, including an indication of the type of a variable may aid the programmer. As mentioned above, Hungarian Notation expanded in such a language (BCPL).
  • In complex programs with lots of global objects (VB/Delphi Forms), having a basic prefix notation can ease the work of finding the component inside of the editor. Typing btn and pressing causes the editor to pop up a list of Button objects.
  • Applying Hungarian notation in a narrower way, such as applying only for member variables helps avoiding naming collision.

Read more about this topic:  Hungarian Notation

Famous quotes containing the word advantages:

    For, the advantages which fashion values, are plants which thrive in very confined localities, in a few streets, namely. Out of this precinct, they go for nothing; are of no use in the farm, in the forest, in the market, in war, in the nuptial society, in the literary or scientific circle, at sea, in friendship, in the heaven of thought or virtue.
    Ralph Waldo Emerson (1803–1882)

    [T]here is no Part of the World where Servants have those Privileges and Advantages as in England: They have no where else such plentiful Diet, large Wages, or indulgent Liberty: There is no place wherein they labour less, and yet where they are so little respectful, more wasteful, more negligent, or where they so frequently change their Masters.
    Richard Steele (1672–1729)

    ... there are no chains so galling as the chains of ignorance—no fetters so binding as those that bind the soul, and exclude it from the vast field of useful and scientific knowledge. O, had I received the advantages of early education, my ideas would, ere now, have expanded far and wide; but, alas! I possess nothing but moral capability—no teachings but the teachings of the Holy Spirit.
    Maria Stewart (1803–1879)