Recently I've been working on some .net code at Microsoft UK. Part of the daily build process involves checking the code submitted into source control against design guidelines, some of which are listed on MSDN. This is all very nice, especially when it's automatic, but a thought occurred, why is hungarian notation considered harmful?
Never heard of hungarian notation? In the DOS years Dr Charles Simonyi, Microsoft's chief architect introduced an identifier naming convention that adds a prefix to the identifier name to indicate the functional type of the identifier, a pointer to X would become pX, a boolean value would be labelled fBool to indicate it was a flag and so on. When Charles Petzold's Programming Windows was released thousands of Windows developers read about it for the first time, and it became common practice.
It is a simple reminder of the type of a variable. Of course when variable types change you should then have to rename the variable, as the prefix will have changed. Is this going to happen? Doubtful. As an example there's wParam in 32 bit Windows. It changed from a 16-bit value (w stands for word) to a 32-bit value (which should have been dwParam).
So hungarian fell out of favour, so much so that some people will "ding" you if you use it in an interview at Microsoft. One of the arguments is "Intellisense helps you so much you can hover over a variable and see what type it is". This is what I object to, intellisense.
Aside from making us all very lazy ( I'll just enter a . and Visual Studio will list all the methods for me), which makes for embarrassing instant messages or job interviews when you can't remember, a reliance on intellisense to prompt you means that you expect it everywhere, which is not realistic. I find it hard to believe that everyone has access to Visual Studio to test and recompile everywhere. No-one has had to edit an aspx in notepad for that one quick fix? No one uses editors other than Visual Studio? What about the Mono project, is there an intellisense editor for Linux?
The point? I'm not sure I have one <g> (hey it's a week till I get married and T is away for her hen weekend, I'm entitled to ramble). I don't think hungarian notation should have been so quickly dismissed, personally I like seeing internal variables prefixed with _, bools marked as fHasItGoneWrong. Maybe someone ought to come up with a new set of prefixes for C# and the .net FrameWork, just to start the debate up again.