quote: Original post by Countach
For example, with 'dwIndex' what does the extra 'dw' prefix tell you?
Nothing, since an index is always an integer.
That's the very reason for using Hungarian Notation, thanks for proving my point . In your example, index is NOT an integer, it's a DWORD. Meaning it will ALWAYS be 4 bytes. For 32-bit operating systems an integer is also 4 bytes, but that's just a coincidence. Back in the 16-bit OS days, an integer was 2 bytes, and when we switch to 64-bit OS it will be 8 bytes. My point being tho, it is a waste of memory to always create your Index variable as an integer if it only needs to be a short. And you'll run into bugs if Index needs to be an unsigned int rather than a normal int. Hungarian Notation allows you keep track what type it really is.
quote: Original post by Anonymous Poster
Houdini:
"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."
When writing hungarian notation you must remember the type of 'ButtonCount' when writing 'ButtonCount' otherwise you would not write the right prefix. Wouldn't it be better to just remember the type of 'ButtonCount' when declaring x than remember this all the way troughout the function?
Using Hungarian Notation with small projects will help you to remember the variable type because you are typing it's abbreviation constantly. Also, looking at the function above you to see the variable type is much faster than loading up the header file to check it. If no functions around it use it, no biggy, load up the header file. Remember, Hungarian Notation isn't primarily used to help WRITE code, but it help DEBUG code.
quote: Original post by Anonymous Poster
Houdini:
"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."
Agreed, if the coder has written the right prefix. But if I am debugging I should now the code good enough to know what type this variable is.
You must have never worked on a VERY large project, and/or never worked in company as a programmer. My company's program I'm working on, as of today, contains 484,000 lines of code. There are tens of thousands of variables in the program. Even if I wrote the whole program myself I wouldn't remember every single variable type.
Which brings me to my next point. I didn't write the program. The very first thing they had me do when I started working here is fix bugs, and I had never even seen the source code before. Although the program used SOME Hungarian Notation (m for member variables, which helped out TREMENDOUSLY) I constantly had to search to find variable declarations thoughout it's 2040 files. Not fun.
quote: Original post by Anonymous Poster
Houdini:
"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."
If I would print out a hardcopy I surely would not care wether the variable is a short or an int. The only variables I would have to do a mouseover on are the ones which are members of a class or globals. I mean the function shouldn't be so big it won't fit on max 2 pages. If I was debugging using the hardcopy I would get to know a little more about the function so that I at least know what type the variables are.
Of course you'd have to search before hand to find out if a variable is a local, global, or member variable. I've had a few times where an algorithm just wasn't working correctly so I printed off the function and had someone else look at it. With Hungarian Notation they know the variable type and don't have to look at multiple other printouts just to make sure the variable types match up.
quote: Original post by Anonymous Poster
Houdini:
"People who use C++ normally wouldn't have this problem. For instance all of my variables are kept private in classes with a Get and Set function for each variable that may need to be changed outside the class.
So how do you know the type, then?
You look at the function/documentation. Remember that Hungarian Notations primary use is for debugging, not for developement. If I create a library I don't want to force other people to use Hungarian Notation by using it in the function names as well. And properly written code should have no global variables so that won't be a problem. People who use that library would use it just like any other code, and it won't break their own naming convention.
quote: Original post by Anonymous Poster
Houdini:
"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."
Overcommenting is extremely irritating.
Yes, but many people don't consider that overcommenting. In very large programs with many people coming in/out of the company, Hungarian Notation is an unbelievable asset.
- Houdini
Edited by - Houdini on December 4, 2000 11:46:10 AM