CamelCase VS Hungarian notation, which is better?

This is a discussion on CamelCase VS Hungarian notation, which is better? within the C++ Programming forums, part of the General Programming Boards category; I am a C++ programmer, and I always used Hungarian notation. However, today I was told that in .NET coding ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    284

    Question CamelCase VS Hungarian notation, which is better?

    I am a C++ programmer, and I always used Hungarian notation.
    However, today I was told that in .NET coding standards, Hungarian notation is not reccommended. I shall use CamelCase.

    Is that to say, naming a varible like this:

    Code:
    int nNumber;
    is not recommended?

    What do you guys think? CamelCase and Hungarian notation, which is better?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,602
    They are two different things. "Camel Case" refers to a variable naming convention where the first letter of individual words in a variable name is capitalised. "Hungarian notation" refers to variable name decoration that identifies either the purpose or the type of the variable, depending on which variant you use. In your case, nNumber is a variable name in camel case that uses Hungarian notation to denote its type (if my guess is correct).
    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. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    There are many arguments against Hungarian Notation (they should be readily available through a search). One argument is that it is difficult to keep the type abbreviation part of the name correct when you are changing the code. So if you changed that number to a double, then you would have to remember to change the prefix as well, and do that everywhere the variable is used. Also, most modern IDEs make it easy to see the type of a variable by mousing over it, so there is less need to explicitly provide that information in the variable name.

    The codeline I work on actually uses a sort of Hungarian notation, and it isn't that bad. But you generally want to use commonly used and understood styles so it is probably best to stay away from full Hungarian in new code.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,602
    There are many arguments against Hungarian Notation (they should be readily available through a search).
    Those are mostly against the type identification variant of Hungarian notation, methinks. The main problem I think the purpose identification variant has is that it is usually made redundant by well chosen descriptive variable names. One good use could be in scope identification with respect to member variables in C++, mainly because this->member is rather uncommon syntax, from what I see.
    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. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    With Hungarian Notation, prefer the apps approach vs the systems approach, IMO. Even so, there are still drawbacks.

    I originally hated underscores; i.e. get_var. But I found it to be easier to deal with later on. Especially if it ever comes to adjacent capitals; camel case doesn't provide as much distinction or emphasis IMO.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. is prefixing by Hungarian notation important?
    By MathFan in forum C++ Programming
    Replies: 16
    Last Post: 06-01-2005, 02:15 AM
  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