Hungarian Notation The Right Way

posted on 2005-05-19 at 22:39:46 by Joel Ross

Joel Spolsky nails it. There's more to his article than Hungarian Notation, but that's what I found that I really liked. If you don't, you should read Joel. He has some great articles and is fairly well known. Not to mention, he's got a great first name!

It’s a long article, and in this day and age, no one reads that much right? You should - you'll find out the history of Hungarian notation. But since most probably won't, I'll summarize it. Hungarian Notation is good to distinguish a variables use, not it's type. Take coordinates for example. Both X and Y coordinates are the same type, say int. But if you are managing coordinates, you don't want to mix those. The compiler won't help you. Nor will "system" hungarian notation - declaring variables as iCoord1 and iCoord2. But declaring them as yCoord1 and xCoord2 makes it pretty obvious if you assign one to the other that it's wrong.

But the compiler won't help you there either. It would be better to wrap those in a custom type so that any cross use would be caught by the compiler. That assumes you have types, unlike ASP and VBScript.

UPDATE: I found a post from Gregg at the MSDN Blogs saying the same thing.

Categories: Development