is prefixing by Hungarian notation important?

This is a discussion on is prefixing by Hungarian notation important? within the C++ Programming forums, part of the General Programming Boards category; Hi! Right now I'm trying to teach myself a standard way of coding. That includes how to annotate function and ...

  1. #1
    Registered User MathFan's Avatar
    Join Date
    Apr 2002
    Posts
    190

    is prefixing by Hungarian notation important?

    Hi!

    Right now I'm trying to teach myself a standard way of coding. That includes how to annotate function and variable names, where to put what in a file etc.

    The other day I found this document. What struck me was this:
    Variable names should be prefixed by Hungarian notation.
    Do I really need to do that? If you look at the table of the prefixes listed on that page, all my class vars should like:

    Code:
    int m_iSomeVar;
    float m_fSomeFloat;
    I have never prefixed my vars before, so to me it looked a little odd.

    My question is: Do I need to using this kind of prefixing, or is it OK to continue without it?

    Thanx alot
    The OS requirements were Windows Vista Ultimate or better, so we used Linux.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,531
    Well a board search will show up what I think about it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    No, it's not important IMO.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    It should be avoided like the plague.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #5
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    Why is hungarian notation so bad? It let's you know what type variables are without having to go back and look them up.

    How does the programming industry view hungarian notation? Does your workplace use it?
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,531
    Hungarian Notation

    > Why is hungarian notation so bad?
    1. It destroys readability by putting a bunch of garbage on the front of every symbol.
    2. You rapidly run out of meaningful single letters - does 'u' mean unsigned or union for example?

    > It let's you know what type variables are without having to go back and look them up.
    Sure, if everyone uses the rules properly, but how often does that happen. Moreover, there are many local variations, so even if you manage to learn one set of rules, you have no information when you look at someone elses code from a different environment.

    Besides, I say if your function no longer fits on screen, you have way more problems than simply not knowing what the types are.

    > Does your workplace use it?
    The fact that my previous place used it so badly was a contributing factor to me leaving for somewhere more sane.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    Quote Originally Posted by Salem
    Quote Originally Posted by The Brain
    It let's you know what type variables are without having to go back and look them up.
    Sure, if everyone uses the rules properly, but how often does that happen. Moreover, there are many local variations, so even if you manage to learn one set of rules, you have no information when you look at someone elses code from a different environment.
    I agree with Salem. Since C++ is a strongly-typed language anyway, there's no real reason to keep type information in the variable name. It also makes it a hastle if you ever have to change the type of one of your variables.

    However, I like Hungarian notation. It can be very useful if used correctly. Take a look at the this article.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  8. #8
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    For what it's worth, I prefer to use descriptive names rather than hungarian notation to try to keep track of what a variable is and it's type. I also find significant use of typedefs, ala Windows, to be very distracting. I'm also at odds opinions such as:

    >> Besides, I say if your function no longer fits on screen, you have way more problems than simply not knowing what the types are.

    I personally find that reading through a long function is easier than jumping back and forth between a multitude of functions, particularly if the goal is to keep the functions short, rather than reuse.

    I certainly understand the rationale for use of hungarian notation, typedefs, and reasonable size functions. I believe that each programmer and each employer decides for themselves where their comfort zone is.
    You're only born perfect.

  9. #9
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    If you ever need to know the type of something just hover over it in the IDE and the IDE will let you know. There is never any need for type information in variable names.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  10. #10
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    Hungarian Notation has been misunderstood and used incorrectly, even by Microsoft.

    The bottom of this article discusses how Hungarian Notation should be used.

  11. #11
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    yep read it couple times, still dont agree. With modern IDE's there just isnt any need whatsoever to obfuscate your own code unnecessarily and thats exactly what hungarian notation does, it destroys any readability the code has and for that reason alone it should not be used. It really doesnt do anything useful for you at all.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  12. #12
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    Did you really read the article carefully?

    IDEs only tell you what the type is. Hungarian Notation was never meant for telling you what the type is, but what kind of variable it is. It's a naming convention to help clarity. Your IDE might tell you it's an int, but it won't tell you what kind of thing it's measuring (length of something? a counter in a loop?).

    Code:
    int iHead; // index in something
    int cShots; // a counter

  13. #13
    C(++)(#)
    Join Date
    Jul 2004
    Posts
    309
    Quote Originally Posted by Dante Shamest
    . Your IDE might tell you it's an int, but it won't tell you what kind of thing it's measuring (length of something? a counter in a loop?).

    Code:
    int iHead; // index in something
    int cShots; // a counter
    I fail to see how anyone would assume cShots meant "Counter for Shots", and not "A char variable named cShots" without looking at the word "int", which automaticly makes the use of hungarian notation pointless right there.

    Descriptive names are for more better:
    Code:
    int HeadIndex; //index in something
    int ShotCounter; // a counter
    It isn't that much more to type, and far more descriptive.
    To code is divine

  14. #14
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    heard of typedef??
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  15. #15
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    The main idea is that if you use it consistently, it becomes a mnemonic: saves typing, while not losing clarity.

    I'm sure none of you do this:

    Code:
    for( int indexInList = 0; indexInList < list.size(); ++indexInList )
    { // blah }
    But rather something like this:

    Code:
    for( int i=0; i<list.size(); ++i )
    Saves typing, but you don't lose clarity. That's similar to Hungarian Notation. Prefix your variables with suitable letters, and you'll gain.

    I fail to see how anyone would assume cShots meant "Counter for Shots"
    Apologies. Perhaps nShots is more commonly used.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. hungarian notation
    By KIBO in forum General Discussions
    Replies: 61
    Last Post: 01-11-2010, 10:42 PM
  2. CamelCase VS Hungarian notation, which is better?
    By meili100 in forum C++ Programming
    Replies: 4
    Last Post: 04-22-2007, 09:31 PM
  3. Hungarian Notation
    By FOOTOO in forum C Programming
    Replies: 6
    Last Post: 05-20-2005, 08:35 PM
  4. Hungarian Notation POLL
    By maxhavoc in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 06-21-2004, 10:52 AM
  5. hungarian notation
    By confuted in forum C++ Programming
    Replies: 2
    Last Post: 07-28-2003, 01:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21