Hungarian Notation - Do you use it?

Pages: 12
Regarding Duoas's link http://www.cplusplus.com/forum/general/39793/#msg214882
Although using a "syntactic" parser could be helpful *

@darkestfright: ¿why don't just make it public? ;)

*¿back to system hungarian?
Last edited on
it causes problems if the type has to change at a later time.
That's pretty much the point of encoding the type into the name of the variable. If you change the type of the variable and hence the name the compiler will show you all the places where that variable is used and you can correct what's know maby wrongfully used.

On the other side if you change the type of a variable you probably change the name anyway.

According to Duos's post I use the simplified 'hungarian' notation (whithout being an hungarian): Prefix 'C' for class, 'E' for enum, 'T' for template type, and 'm_' for member variables.

It's too neat to write: CWhatever Whatever; or EWhatever Whatever;
closed account (zb0S216C)
I did at one point. Apparently, Hungarian Notation came from FORTAN. Here's a paragraph from Wikipedia:

Wikipedia wrote:
The original Hungarian notation, which would now be called Apps Hungarian, was invented by Charles Simonyi, a programmer who worked at Xerox PARC circa 1972-1981, and who later became Chief Architect at Microsoft. It may have been derived from the earlier principle of using the first letter of a variable name to set its type — for example, variables whose names started with letters I through N in FORTRAN were integers by default.


Wazzak
Last edited on

That's pretty much the point of encoding the type into the name of the variable. If you change the type of the variable and hence the name the compiler will show you all the places where that variable is used and you can correct what's know maby wrongfully used.


Its almost the antithesis of modern C++ programming thought, or at least generic programming, where I can change the type of the variable and things still work, assuming the type change does not also include a semantic change.

Occasionally I find myself renaming a variable to some other equally useful name just so the compiler can tell me where I have to look. But not too often.
closed account (3hM2Nwbp)
I tend not to use any API that use that notation. (IE. WinAPI; but .NET is great, however)

Lately though, I've been prepending underscores on any internal variables and methods that my classes use. Any users of the class are not affected by what goes on in my little black box. I'm still experimenting.

I referenced this in the last thread about this as well:

wikipedia wrote:

Hungarian Notation becomes confusing when it is used to represent several properties, as in a_crszkvc30LastNameCol: a constant reference argument, holding the contents of a database column LastName of type varchar(30) which is part of the table's primary key.


a_crszkvc30LastNameCol simply doesn't seem very intuitive to me.
Last edited on
It looks like a Polish word to me. It actually detracts from the readability at that point.

You should avoid using symbols that begin with an underscore; those are reserved by the compiler. It would be better to put the underscore at the end.
closed account (3hM2Nwbp)
Ah, I wasn't aware of compilers reserving underscore-prepended symbols. I was simply following the convention I encountered in the STL internals.
closed account (1yR4jE8b)
I have never, not once, ever had a problem using an underscore-prepended symbol. Then again, I *only* use them as instance members, which probably explains why my compilers haven't gotten confused by them.
It simply means you haven't picked one that your compiler uses, which is very likely considering how relatively few they use. However, the standard does reserve all symbols beginning with an underscore for compiler writers, so at some point in the future you could run into problems if you upgrade or switch compilers.
closed account (1yR4jE8b)
noted
I use myXXXX for member variables and inXXXX for function arguments. Other than that I don't use any other prefix's.
edit: wait I also postfix pointers to instances of singletons with _I .
Last edited on
I did when trying to mod Dragon Age. Origis, them Bioware guys seems to love it. Also, that languaged resembled C and was really cumbersome as it had no namespaces and classees, though I liked the switch-case blocks with {}s after the case line.

Now, I use
ClassName
variableName
_tempVariable -- for methods, excluding thread loop functions and main function.
NamespaceName (C#) namespacename (C++)
CONSTANT_NAME (C++) ConstantClass.constantName (C#)
closed account (iw0XoG1T)
I love the progression of this thread particularly how Joel Spolsky's article has become Doas's post.

What I enjoyed most about Spolsky's article was how he described the progression programmers go through. In my case it is was very true, I certainly remember wasting my time reformatting other's code.

But I noticed that what I consider good and bad is definitely influenced by what I'm reading. I have gone from oop is always good, to oop is bad, to somewhere in the middle. I have gone from throwing exceptions is good to and users need error messages, to throwing exceptions is quite often a sign of bad and error messages more times than not only confuse end users.
Last edited on
Topic archived. No new replies allowed.
Pages: 12