<Rant topic='Hungarian'>Damn I get mad about stuff!

Some things get me really fired up.

Not your typical high school debating issues (abortion, euthenasia, religion, ho hum?) -- but Hungarian naming standards. Now that's a fiercesome topic! Full of emotion! A political minefield!

Oh I've tried to code without Hungarian. I've followed the new standards. But it's a crock! A marketing foible!

Getting rid of Hungarian is just a terrible piece of 'Fashion' that will later be looked back on with regret.

'Well we've got .Net now, so we'd better make all of our code look minimalist, clean and non-technical...'

'Everything's an object, you know, like Java, so let's do what sun does'

[Rant continues, with comparisons...]

You may feel that for an API (a public API that you are going to foist onto other people) will *look* better if you avoid hungarian. That's kind of true.

But in such a case the details of your API are largely a marketing exercise and have little to do with 'Maintainability.'

But for real code, the guts of your code, the sort of code you write every day and work with every day, nothing can beat Hungarian.

Arguments I've seen against Hungarian

  1. "Hungarian makes code harder to read. for example: m_dblPrice vs Price."

    No, it isn't harder to read, it's more informative and easier to understand.
    "Price" alone tells you much much less than "m_dblPrice".
    The reader's digest condensed version of "Slaughterhouse 5" is a quicker read too. But that doesn't make it better.
    To a seasoned developer, "m_dblPrice" is easier to read than just "Price". Your mind is not distracted by questions like, "hang on, is this the pricing object? or the price parameter? or the local static price variable? or the module level... let me just hover over it, or right click on it and then... oh!" You get the idea.

  2. "With Intellisense you can find out the type and scope of a variable more easily than previously."

    Not as easily as you can with Hungarian, baby!
    You can only find out one variable at a time
    Without Hungarian, you have to actively seek that information out.
    Intellisense doesn't help if the code is printed out, or pasted into an email, or provided on a web page, or being viewed in any other way. (You probably read a lot of code outside of the IDE, just like I do.)

  3. "It takes longer to write "m_dblPrice" than it does to write 'Price'"

    Yes but it's quicker to use and maintain, because you can find it faster.
    Roland Weigelt has excellent pictures that demonstrate this.

  4. "In Hungarian, if you change the type of the variable then you have to change the name. What a mess!"

    This is a very good point, and I concede it utterly.
    However, in Whidbey, refactoring support promises to be a lot better.
    You will be able to rename a variable with ease.

  5. In Hungarian, if someone puts in the wrong prefix, it will mislead you.

    True enough. But FX-Cop can gobble up problems of this sort. You needn't lose any sleep over it.

The main reason I've seen for ditching hungarian is:

"But this is the new way."

Come here and say that! I dare you! You'll feel the stinging wrath of my sarcastic wit! You will be sorry, dunderhead.

</Rant>

 

My book "Choose Your First Product" is available now.

It gives you 4 easy steps to find and validate a humble product idea.

Learn more.

Avonelle Lovhaug on February 10, 2004 22:53 sez:

Sorry, I have to completely AGREE with you.

Hungarian rules!


ABO on February 11, 2004 13:58 sez:

Have fun with 1000 different prefixes! :) I've dropped the Hungarian naming convention and I'm feeling quite fine


Benjimawoo on February 16, 2004 06:14 sez:

Okay, so hungarian prefixes make it easier to see exactly what you're working with, but what makes it easier still is well named (Okay, they're slightly more verbose/longer) variables in well structured classes.

Just what I think, though. Ignore at will.


Scott on February 16, 2004 08:11 sez:

I have recently had a newby coder wonder why a change made to a member variable in one procedure was not reflected in a subsequent procedure. The fact that he had declared the member variable as lngDealId, omitting the m prefix, and lngDealId was the name of an existing procedure level variable was found to be the cause of his frustration. He has since been made to read over the basics of Hungarian Notation and use it even during the most basic coding tasks (e.g. Excel macros/functions)

Does FX-Cop require much setting up to enforce HN? Can anyone recommend it from experience?


Thomas Eyde on May 25, 2004 06:10 sez:

You are not serious, are you?


secretGeek on May 25, 2004 17:24 sez:

hi Thomas -- yep, i am serious.
straight up let me qualify that i don't think we need to hungarian prefixes for classes in the FCL or classes of our own.

I recommend them for basic types (integer, string and the like) and user controls (txt, btn and so on). Also, prefixes for scope (except for local), and for constants.

So this isn't Extreme Hungarian. I'm only advocating about thirty to fifty prefixes.

Hungarian is a maintenance issue -- but most .net code is too new for people to realise that maintenance is gonna be an issue. but Oh it will be. big time.

If you still disagree, please say so -- i am fairly interested in opinions about this stuff.

thanks again Thomas

Leon



Thomas Eyde on May 26, 2004 01:36 sez:

I used to be a fan of Hungarian some years ago. I remember a heated debate about 1 or 3 letter prefixes I had with a coworker. Later I had a new heated debate on scoping prefixes, with or without underscores.

When I was introduced to extreme programming and, most important to me, unit testing, the parole was: Forget about type, express the variable's intention. You would always know the type of the variable in a given domain as long as the name is descriptive.

A name would be a string, so would socialSecurityNumber. age would usually be an integer, while person and user would be instances of Person and User or some derivative of those.

Most important I came to learn it is all about preferences. I have mine, you have yours, but we can't really question each other's preferences before you have tried mine and I yours. I lost my interest in Hungarian the moment I tried to use descriptive names instead.

I like the '_' prefix for class variables. I programmed a lot in VB6 before C#. Names in VB6 can't start with an '_', so my class variables there was named mySomething.

Also scoping prefixes can be difficult, but thats more a cultural issue. I don't know about English keyboard layouts, but to type 'm_' you have to type 'm' + [shift] + '_'. I think the combination is too clumsy.

These are my experiences. I am perfectly happy wothout Hungarian, and I don't think it is any harder to maintain my code.

I can see there are certain scenarios where Hungarian works very well. Is it so much better than not using it? For me it isn't, but then you may have experienced something which I haven't.


secretGeek on May 27, 2004 04:19 sez:

Thanks for the excellent response Thomas. These are the best presented arguments I've heard yet.

The only case I can think of that falls through the gaps is when it isn't obvious whether a variable is long/integer, for example. But if that's the only area of confusion, then tooltip text is more than adequate.

I agree that underscores make for sore pinky-fingers!

cheers
lb


(By the way, I read every comment and often respond.)

Your comment, please?

Your Name
Your Url (optional)
Note: I may edit, reuse or delete your comment. Don't be mean.