Here’s how Hungarian Notation came to be known as it is today.
Literally and mundanely, the notation had indeed been invented by a Hungarian. His name is Charles Simonyi. He was born in Budapest in 1948, and for more than a decade he was senior programmer at Microsoft in Redmond. His invention of the notation dates back to the early seventies, however, and he used it during his degree work at Berkeley and later when he was working at Xerox PARC. He disliked the way that names in C programs could stand for any kind of variable. This was for ever leading to mistakes. “If only,” he thought, “the names of the variables themselves gave useful information about their type ...”. And so the idea of Hungarian notation was born, in which each variable is prefixed by lower-case letters indicating useful things about it.
He had the chance to implement his ideas when he joined Microsoft in 1981. The programmers there looked at the convoluted, vowel-less variable names produced by his scheme and, like everyone else who has come into contact with them since, must have said something like “This might as well be in Greek—or even Hungarian!”. They almost certainly had in mind as well another kind of mathematical system called Polish notation. They put the two together and made up the name Hungarian notation.
Charles Simonyi points out the following features in favour of his naming scheme: When confronted with the need for a new name in a program, a good programmer will generally consider the following factors to reach a decision:
1. Mnemonic value—so that the programmer can remember the name.
2. Suggestive value—so that others can read the code.
3. "Consistency"—this is often viewed as an aesthetic idea, yet it also has to do with the information efficiency of the program text. Roughly speaking, we want similar names for similar quantities.
4. Speed of the decision—we cannot spend too much time pondering the name of a single quantity, nor is there time for typing and editing extremely long variable names.
Arguments against Hungarian Notation point out that it is most widely used in C++. But C++ is a hybrid language ( Oh! Is it? I don’t believe you). You can mix objects with primitive data-types, that is the simple reason why. For a pure OO, strongly-typed language, you can do away with Hungarian Notation.
Also, in C++, what is often more important to know about a variable is not its type, but its scope (local, function arg, file static, member, static member, global etc). This can be easily encoded with a Hungarian-style notation, such as what MFC uses, with m_ for member, c_ for static members etc.
Hungarian Notations's main disadvantage may be when the name does not match the type. eg. you originally had a single byte for a value, but the specs change and now you need an unsigned long - that means not only must you change the type of the declaration - in one place - but the name of the variable everywhere it is used.
Staunch Critics of Hungarian Notation see it more of a commenting style and they have every logical reason in the world to think so.
You can have a great insight by reading the article written by the man behind all this visiting the following link: http://msdn.microsoft.com/library/default.asp?url=/library
/en-us/dnvs600/html/HungaNotat.asp
No comments:
Post a Comment