Hungarian Notation - Do you use it?

Pages: 12
Jul 19, 2011 at 8:24am
Hey,

I was just thinking to myself, how many of nowadays programmers actually use Hungarian Notation?

I know I haven't before, but I came across it 2 days ago and have been comfortably using it since then.

For those who don't know, Hungarian Notation is when you name your variables based on their type/scope, such as

int nBobsPaycheck = 35;

and

float fPi = 3,14159265;

Do you use Hungarian Notation?
Last edited on Jul 19, 2011 at 8:25am
Jul 19, 2011 at 8:27am
no
Jul 19, 2011 at 8:35am
A BIG FAT NO!!!! Whoever invent that notation has caused un-told sufferings for C++ beginners but luckily it is restricted to Windows API. Can you image this notation is carried over and adopted for Unix/Linux system calls API ? Or even carried over and adopted for Java API ? The reason it is contained within Windows API speak of it's "popularity or non-popularity" within the developers community isn't it ?:P
Jul 19, 2011 at 9:13am
Nope. I don't see a point.
Jul 19, 2011 at 9:16am
Since we are on the notation topic, how you all give your variable naming ? For C++ data members I like to use m_XXX or mXXX. For static I like to use s_XXX. That's it, the rest are just descriptive names with no prefix or suffix.

Come and share your own variable naming convention :P
Jul 19, 2011 at 9:17am
I find my code to be very much easier to read with this, keeping track of which variables shouldn't be used at certain places.

@sohguanh That is Hungarian...
Last edited on Jul 19, 2011 at 9:18am
Jul 19, 2011 at 9:18am
So AngelHoof are you by any chance a Hungarian ? :P
Jul 19, 2011 at 9:20am
For C++ data members I like to use m_XXX or mXXX. For static I like to use s_XXX


That is Hungarian Notation.

And I'm Swedish.
Jul 19, 2011 at 9:22am
closed account (z05DSL3A)
Yes and no (and variants in-between).

Edit:
For C++ data members I like to use m_XXX or mXXX. For static I like to use s_XXX

I would also say that that is (part) Hungarian Notation.
Last edited on Jul 19, 2011 at 9:52am
Jul 19, 2011 at 1:30pm
I use my own muddled and broken variation of Hungarian Notation when working on projects that I can guarantee no one else will ever need to see the code of.
Jul 19, 2011 at 2:16pm
I like to use the 'm' to indicate a member, but I don't put the type in the variable name. Mainly because it's pointless and it causes problems if the type has to change at a later time.
Jul 19, 2011 at 4:25pm
http://www.joelonsoftware.com/articles/Wrong.html

Hungarian notation was perverted by Microsoft. It is supposed to attach a semantic value to a variable name, not type/scope.
Jul 19, 2011 at 5:02pm
SO... DAMN... UGLY!
no prefixes\suffixes at all for me
Jul 19, 2011 at 6:21pm
closed account (1yR4jE8b)
I try to use the notation used by the Standard Library of the language as much as possible; so when I code in C++ it goes something like this:

1. class_names
2. functions_names
3. variableNames
4. CONSTANT_VALUES

I also like to prefix member variables with an underscore, but mostly to help code-completion be a bit smarter and so that I can use the non-prefixed name for accessor/mutator functions:

1
2
3
4
5
6
struct Foo {
  int& x();
  int x() const;
private:
  int _x;
}


Of course, this goes out the window if I'm mainly using a non-standard library that doesn't do something similar to this. It's all about adapting to the current library/standard/language.
Last edited on Jul 19, 2011 at 6:21pm
Jul 19, 2011 at 7:08pm
I don't use Hungarian. It's ugly, and confuses anybody who doesn't know it.
Jul 19, 2011 at 8:30pm
it causes problems if the type has to change at a later time.


Ah... Excellent point, hadn't even considered that!
Jul 19, 2011 at 9:05pm
closed account (1yR4jE8b)
Encoding the type of a function into the name (so-called Hungarian notation) is brain damaged—the compiler knows the types anyway and can check those, and it only confuses the programmer.

--Linus Torvalds
Jul 19, 2011 at 9:35pm
So nobody read what Duoas posted? :)
I don't use it, but after reading that thing, I'm remembering several cases where I should have..
Jul 19, 2011 at 11:27pm
I think the Apps Hungarian from Duoas' post is the best notation to use, but I don't use it either. :\
Jul 20, 2011 at 12:25am
Aside from this point (certainly the biggest reason NOT to use it):
it causes problems if the type has to change at a later time.


it is also quite impossible to do inside any template function unless you go with a "t" prefix, which is about as useful as naming every single one of your classes beginning with the letter "C".

Pages: 12