by Kzinti » Jan 15, 2003 @ 12:40am
Hungarian notation has both advantages and disadvantages.
1) It has the general advantages of having a naming convention.
2) It serves to document types in a weakly typed language. This doesn't apply as much for C++ as it does for C.
But Hungarian has serious drawbacks:
1) Hungarian ignore the use of abstract data types as base types. Because of this, it forces programmers to worry about manual type checking instead of letting the compiler check the types more rapidly and accurately.
2) It combines data "meaning" with data "representation". This is so bad, I don't even know where to start.
3) It encourages lazy, uninformative variable names. (ie: "hWnd" vs "MainMenuWindow").
These ideas are taken directly from "Code Complete" mentioned up there, and I totally agree with the author's point of view. Hungarian simply sux. It isn't all that bad when programming in C, but it is a real problem when dealing with C++. It encourage slopiness in the architecture. If you want a good example of a crappy architecture, look no further then MFC. It's an old library that was written before C++ had a standard. I am not saying MFC wasn't good when it came out, it is simply a product of it's time.
Now prefixing all class names with "C" or even "T" or whatever is not that bad, although I prefer to start my type definitions with an uppercase letter. This way, the prefixing is not needed.
To anyone who will argue that having the type described as a prefix "pwstr" is useful because you don't have to go check the type of a variable when you use it: that's exactly why prefixes shouln't be used. To me, "playerName" is infinitely more clear then "pszname", and "pszPlayerName" is not adding anything. It even become a problem when I change my variable to a "std::string".