Advertisement

How many of you uses Hungarian notations?

Started by November 30, 2000 11:55 PM
81 comments, last by vbisme 24 years, 1 month ago
I used to use Hungarian notation religiously, but I''ve recently dropped it. Here''s my reasons:

  1. I do a lot of non-Windows coding, and Hungarian mixed with other styles looks funny, IMO
  2. I''ve never needed the type information. As has been mentioned, a lot of compilers give you type info on mouseover. In addition, I keep my variable declarations as close as possible to where they are used, so the type info is generally readily available to me. The only exception to this is globals and member variables.
  3. I tend to use fairly long variable names (8-15 characters on average), since I try to make them descriptive as possible. Adding Hungarian prefixes tends to make them too long, especially when I have several on a line. The longer names also make including the type less important, since I can usually get a pretty good idea of the type from the name.


I do still use some elements of Hungarian, though. I like using the g_, s_, and m_ prefixes, and I preceed classes with C. That''s about it, though. I personally really like the way my code looks now, and the people I work with like it too, so that''s all that really matters.
i wish everyone used it. i do. when i pick up someone else''s code and have to work with it, if it''s not using hungarian notation, my job is made about 10x harder. it creates self documenting code, at the cost of a few extra characters, and that is tremendously valuable. i''m not saying hungarian is the only way, but it''s a standard. when i see code not using hungarian, probably 90% of the time the naming conventions are undisciplined and unpredictable. 10% of the time they make sense and are consistent and self consistent. empirically speaking - i work at a company where almost all of the engineers use hungarian. when i look at some code, i have no idea who wrote it because people adhere to our style guidelines very well, but i can always immediately start following it. it really does work.
Advertisement
I cerainly use the Hungarian notation, and find it a very useful thing not only for understanding others'' code, but alos your own...

------

"You see, Lone Star, Evil will always triumph because Good is dum !" - Space Balls

"Please Wait While Loading User" - Windows 98 Operating System
[ Libraries - STLport | boost | SDL | wxWindows ]
[ Manuals - MSDN | STL Docs ]
[ Compilers - VS.NET | MingW | DJGPP ]
[ Editors/Tools - EditPlus 2 | Anjuta | Dev-C++ ]
I think if you need a prefix to remind you what the variable''s type is you probably did not give it a descriptive name.
huh? i think

"cWindows" (count of windows)

is just as desriptive as

numWindows
NumWindows
numOfWindows
NumOfWindows
NumberOfWindows
numberOfWindows
num_windows
num_of_windows
number_of_windows

and there aren''t so many different ways for a person to name the variable.

i love seeing a variable named like this:

"window"

what the hell is that?

a pointer to a window? a struct? an index to an array of windows? a string? an enum? is it a global variable? a member variable? a static variable?

and

"windows"

is it an array? a count of windows? a string? a struct? an enum? is it a global variable? a member variable? a static variable?

the subjectivity of the english language (any language really) is just not as effective for encoding the intent of a variable in the variable''s name as a "code". yes it takes longer to get use to. the first time i had to work with hungarian, i was a wreck. it was a nightmare. but after a while, it clicked, and i loved it. and i think that''s the problem here. people that don''t like it have never HAD to use, and thus have never been able to experience its benefits.
quote: Original post by Anonymous Poster

I think if you need a prefix to remind you what the variable''s type is you probably did not give it a descriptive name.


Uhhh, that makes no sense.

You mean, you can tell from a variable called "ButtonCount" or "NumberOfButtons" whether it''s a byte, short int, unsigned int, int, long, unsigned long, etc. The only way to tell is to include the type in the name, which is exactly what Hungarian Notation does.


- Houdini

- Houdini
Advertisement
quote: You mean, you can tell from a variable called "ButtonCount" or "NumberOfButtons" whether it''s a byte, short int, unsigned int, int, long, unsigned long, etc.


Do you really need to know the right type? You know that it''s a number of some sort, and you don''t need to know any more to understand the algorithm. If you need the type when coding, then you nearly always remember it. And if you don''t remember it, then I am almost sure that you don''t remember the name either. So you have to find both for example in the class declaration, or function declaration, not too much work. Local variables are often declared near where they are used, so you will see the type immediately.

And if you are debugging, I am sure you take a deeper look at the algorithm first, and hence learn the types. So no need for hungarian notation there either.
quote: Original post by Houdini

Now theres a shocker. You mean the person who hates comments that make code easier to understand, also hates Hungarian Notation which also makes code easier to understand? GASP!

jk of course =)


- Houdini



I''m against productivity when it means i have to do extra work


cmaker- I do not make clones.
quote: Original post by fredizzimo

Do you really need to know the right type? You know that it''s a number of some sort, and you don''t need to know any more to understand the algorithm. If you need the type when coding, then you nearly always remember it. And if you don''t remember it, then I am almost sure that you don''t remember the name either. So you have to find both for example in the class declaration, or function declaration, not too much work. Local variables are often declared near where they are used, so you will see the type immediately.

And if you are debugging, I am sure you take a deeper look at the algorithm first, and hence learn the types. So no need for hungarian notation there either.



You''ll need to know the type if you want to do a for loop from 0 to ButtonCount. No need to declare x as an integer if ButtonCount is a byte, because it''s a waste of space. And if ButtonCount is a unsigned int then you need to make sure that x is also an unsigned int. Or, for instance, if you need to create a temporary variable to hold information in that variable, you need to know the type. So yes, there are most definately times where you need to know the type of a number variable.

As for not remembering variable names, it''s not really an issue. Hungarian Notation is useful for writing code, but it''s even more useful when fixing bugs or reading someone elses code. In those cases the variable is already there, and you don''t have to remember it.

Heck, what are you going to do if you need to print out a hard copy of some code? You can''t use the editor to do the mouseover for the type. You''d have to make sure you printout the declarations of all your variables, even if all you really needed to printout is the one function you are having problems with.

Hungarian Notation is basically a form of commenting. It makes programming a little easier, but mostly it makes bug fixing and understanding someone else''s code much easier. Just like comments.


- Houdini
- Houdini
Hungarian Notation? I luv it!

In fact, I even started using it in PHP recently, hmm.



========
Smidge
www.smidge-tech.co.uk
========
--Mr Smidge

This topic is closed to new replies.

Advertisement