Compellingly Beautiful Software
Products Programming Contact
Back in the days when Charles Symoni was at Xerox PARC, that is, before he went to work for the Evil Empire, he had this interesting idea: add standard prefixes to the names used in computer programs to help readers quickly understand exactly what those names represent. This idea became known as Hungarian Notation, either because Symoni is himself Hungarian, or because the resulting names look pretty strange to the uninitiated.
This simple idea has been the topic of howling religious wars. If you don't like Hungarian Notation, let me ask you: is it the idea of the notation that you think is bad, or is it really some particular implementation of the idea that was bad? We'll readily agree that some Hungarian dialects are horrible, ridiculous, or just plain awful. The dialect shown here is limited in what it attempts to accomplish, and it follows rules that are simple and strict. The result: it's easy to learn, and, once learned, it makes it easier, not harder, to write and read your programs. Some people think that modern high-powered IDEs make the very idea of Hungarian Notation obsolete, but this isn't the case. This notation not only shows the types of variables, it also shows relationships between variables. No IDE can do this better, assuming it can even figure out what those relationships are.
Here are some good reasons to use this notation:
Here are some bad reasons not to use this notation:
So the obstacles are minor, and the payoff is great.
A Hungarian name has two parts: a prefix and a suffix. The prefix tells you what this thing is. The suffix tells you what this thing means.
The prefix is composed from a standard list of elements that a team agrees to use. In our dialect, prefix elements are always lowercase letters, where each letter has a distinct meaning: there are no multi-letter prefix elements. Prefixes can contain several letters, however, because the elements can be concatenated. When prefix elements are strung together, they always compound to the left.
The suffix may be null, that is, it may not exist, because in many cases a prefix alone is an adequate name, especially for local variables. If the suffix is non-null, it is composed from standard words written in CamelCase. The last word in the previous sentence is an example of CamelCase. Underscores are not necessary. When more than one word is needed in a suffix, try to arrange them so that the most important word comes first, with less important modifying words coming after, for example, ColorBlue and ColorRed. Don't use abbreviations in the suffix except for those your team has agreed to use. Part of the reason for using this notation is so that everyone on a team will create the same names, even if they aren't working closely together. Allowing indiscriminate abbreviations destroys this benefit.
When this is done correctly, program texts are found to contain families of names that "grow out from the middle." They make it easy to see how the variables in your program are related to each other. This is one of the greatest benefits of this notation.
Two different Hungarian dialects are presented here: one for Java and one for C/C++. They are very similar. The C dialect was developed in 1990 and has survived years of hard use with little need for change during that time.
© 2004 brising.com