hungarian notation

This is a discussion on hungarian notation within the General Discussions forums, part of the Community Boards category; Originally Posted by Snafuist I haven't seen a sane programmer use either Apps or Systems Hungarian. While Systems Hungarian is ...

  1. #16
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    Quote Originally Posted by Snafuist View Post
    I haven't seen a sane programmer use either Apps or Systems Hungarian. While Systems Hungarian is plain ridiculous, one might argue that Apps Hungarian helps [morons] choosing consistent variable names; but in my opinion, there are far better alternatives, the most prominent one being common sense.
    Your opinion might be easier to swallow if you didn't describe yourself as a "Complete beginner." Things get difficult when dealing with large projects and many programmers, and having an agreed-upon set of rules in place to manage things like variable naming doesn't make us "morons."
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  2. #17
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,632
    Quote Originally Posted by brewbuck
    Not all affixes to variable names are bad. If these affixes help explain the purpose of the variable as opposed to its type, they can help reduce keyboard typing and effort when naming variables as long as they are applied consistently.
    That is why I call Apps Hungarian a uniform way of abbreviating descriptive variable names. Once you are no longer uniform about it, you might as well just be a little more long winded.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #18
    Making mistakes
    Join Date
    Dec 2008
    Posts
    476
    Unless you're writing bigger subroutines with many variables, I wouldn't recommend using it. App Hungarian can help there, but System Hungarian can probably not.
    Last edited by Brafil; 05-08-2009 at 10:24 AM.

  4. #19
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,632
    Quote Originally Posted by Brafil
    Unless you're writing bigger subroutines with many variables, I wouldn't recommend using it.
    Then again, if you are writing such a complex subroutine, then it may be better to move some of its implementation to new subroutines.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #20
    Making mistakes
    Join Date
    Dec 2008
    Posts
    476
    I meant just that. I think nobody can see through 20+ variables. That minimizes the need for hungarian notation.

  6. #21
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >She's probably talking about the difference between Apps Hungarian and Systems Hungarian.
    Yes. It follows much like my view on commenting. If the code says what needs to be said, why put it in a comment? Likewise, if the code tells you the data type, why put it in the name? Apps Hungarian works toward helping you understand the intention behind the code rather than the mechanics. It's a good idea (though whether the execution is good is debatable), and the Systems style ruined it.
    My best code is written with the delete key.

  7. #22
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Could one call it Hungarian notation when for example variables that have to do with counting begin or end with the word "count", variables/enumerator values specifying maximum values begin or end with "max" etc?

    I also noticed in my current wxWidgets project, that when I want to reference a multiline wxTextCtrl*, it is called "editor", but when I need its Windows handle, it is called "h_edit"
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  8. #23
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    At least Microsofts version of hungarian notation is specifically defined. I agree that apps hungarian is brain dmaged, but systems hungarian is useful, particularly when coding in C/C++ when type checking can actually interfere with the compilation process e.g. when converting a 32 bit image into 4 seperate color planes by specifically referencing the dwImage array as a byte array during a copy operation.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  9. #24
    Complete Beginner
    Join Date
    Feb 2009
    Posts
    312
    Quote Originally Posted by brewbuck View Post
    Your opinion might be easier to swallow if you didn't describe yourself as a "Complete beginner."
    I don't know how to describe my programming skills. I'm convinced that there are at most 5 good C programmers in the world (Rob Pike, Dennis Ritchie, Brian Kernighan, Ken Thompson and maybe someone else), and I'm pretty sure that I'm not the fifth. On the other hand, I consider my code to be not as bad as most of the code I've seen so far. But then, I'm mainly interested in the theoretical side of programming (i.e. algorithms and maybe design), so programming decays to a hobby. I'm happy if I know what to do and how to do it in the optimal way; an actual programmer may then implement the stuff, i.e. simply write it down.

    Things get difficult when dealing with large projects and many programmers, and having an agreed-upon set of rules in place to manage things like variable naming doesn't make us "morons."
    I didn't mean to offend anyone, and in particular not you. In fact, I agree with most of the points you made in your first post. On the other hand, it is my firm belief that a good design yields functions with at most ~5 local variables, which any decent programmer should be able to remember for the next 20 lines of code (that's the "moron" part). From this point of view, Apps/Systems Hungarian notation is a bad substitute for good design. If the code is not completely obvious in the first place, increasing the size of variable names doesn't make it any better.

    That being said, having an agreed-upon set of coding rules certainly is a Good Thing. I wouldn't want to read code where the programmer invents fancy names for loop counters. In 95% of the functions I write, the variable names are from the following set: i, j, k, fd, buf, tmp, a(rr), n(ode), e(lem), g(raph), l(ist), h(ash), m(ap), p, plus some descriptive function argument names like window, str, src, dest and so on. Apart from global variable names, this should completely suffice to come up with arbitrary applications.

    Greets,
    Philip
    Last edited by Snafuist; 05-09-2009 at 04:35 AM.
    All things begin as source code.
    Source code begins with an empty file.
    -- Tao Te Chip

  10. #25
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    >> I agree that apps hungarian is brain dmaged, but systems hungarian is useful

    I thought others were arguing the opposite.

  11. #26
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    >> I like descriptive and concise names, although it's often harder to pull out of the top of your had than hungarian notation.
    I often find myself annoyed with my choices in variable names. Maybe I should spend more time thinking about them, and maybe that way they'll behave later on in life.

  12. #27
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Quote Originally Posted by cpjust View Post
    I don't think Hungarian Notation and descriptive names are mutually exclusive. Hungarian Notation is just a prefix to a variable name. So you could have something like:
    lpszFirstName
    which is perfectly descriptive, albeit ugly to look at.
    Until you decide it should be a std::string, then it's a liar.

  13. #28
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by medievalelks View Post
    Until you decide it should be a std::string, then it's a liar.
    That's why I don't use Hungarian Notation for variable types, just the more common notations like m_ for member variables & p for pointers.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  14. #29
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    Transitioning back and fourth from C# to C++ I'm wondering if I should bring over some of what is standard there to here. I personally in most languages use descriptive names, forgetting about hinting at the types, and use _ prefix for private variables, Pascal case for Functions and Class names, object names, variables, etc are Camel Case.
    Here to Deceive, Inveigle, Obfuscate Since 1945

  15. #30
    Making mistakes
    Join Date
    Dec 2008
    Posts
    476
    I think hungarian is difficult to encode at first. "Normal" names are sometimes so easy to rush over...

Page 2 of 5 FirstFirst 12345 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

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

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