Jump to content
  • Advertisement
Sign in to follow this  
becoolnike

do you guys use Hungarian notation?

This topic is 2867 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have heard that Hungarian Notation is not recommended by Microsft and Bjarme Stroustup, the creator of c++. What notation do your recommend?


Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by becoolnike
I have heard that Hungarian Notation is not recommended by Microsft and Bjarme Stroustup, the creator of c++. What notation do your recommend?
My heartfelt recommendation is that you forget you ever heard the word "notation", and just get on with writing the damn code.

If you have to deal in such pedantic terms, then anything *except* Hungarian is the way to go...

Share this post


Link to post
Share on other sites
Ah, the great Hungarian Notation Debate.. soon to fill with flames I'm sure.

However, I'm going to go out on a limb here and say that practically everyone uses a variation on what I like to think of as Modern Apps Hungarian.

Unlike System Hungarian, which encodes type information into the variable name (for example fWidth meaning a floating point type) Apps Hungarian, which iirc was the first Hungarian Notation invented, encodes usage information into the variable name (for example colWidth meaning 'column width' or sName meaning 'safely encoded name').

Now, while there are still those out there who use System Hungarian (and my god have mercy on their souls for it) they, and indeed others, will still encode usage information into the variable names, because that makes sense.

The reason I referred to it above as 'Modern Apps Hungarian' is because instead of using short hand for a variable name, such as colWidth, longer more descriptive names are used; columnWidth for example.

The semantic infromation is still encoded, we just aren't pandering to 80 column screens or editors without syntax completion any more [wink]

There is some variation on this of course; case of laters, underscores or not, pre and post-fix information to indicate scope, but in general I would say "Modern Apps Hungarian" prevails because it makes sense.

Share this post


Link to post
Share on other sites
Quote:
Original post by becoolnike
I have heard that Hungarian Notation is not recommended by Microsft and Bjarme Stroustup, the creator of c++. What notation do your recommend?
They're talking about "Systems Hungarian", not "Apps Hungarian".

Share this post


Link to post
Share on other sites
To expand on what phantom said, the original Hungarian was developed based on the observation that int width; is a dangerous way to handle variables when width can be in pixels, twips, inches, centimeters, or bits. Instead you use pxWidth, and now it's a pixel value. Sadly this was corrupted to re-encode the variable's explicit type, and worse still people actually thought it was a good idea to do so.

Share this post


Link to post
Share on other sites
In short, it was from an era when you couldn't just hover your mouse over the variable name, and get a nice little popup with it's type and comment right there for you. Also, certain compilers could only identify the first x characters in a variable name uniquely (usually 8 I believe).

Now you can easily write int HowMuchWoodCanAWoodChuckChuckIfAWoodChuckCouldChuckWood if you want to.

Share this post


Link to post
Share on other sites
Quote:
Original post by Daaark
In short, it systems hugarian was from an era when you couldn't just hover your mouse over the variable name, and get a nice little popup with it's type and comment right there for you.
Unambigufied ;)
Apps hungarian attaches information to the name that you can't find out by hovering your mouse over something (like in promit's example: whether the int is counting in pixels or inches).

There's a long essay on the corruption of hugarian and it's proper use on Joel on Software.

Share this post


Link to post
Share on other sites
Personally , I just really care about things being uniform. If multiple people are working on the same code, I just want things to be consistent and have some logic behind the structure of variable names.

Share this post


Link to post
Share on other sites
Quote:
Original post by andrew1b
What about Java beans-like style? Do you guys think it's a good idea to use it on C++ code?
Especially in Java and C++ it is silly, in my opinion. As Promit said, there used to be a good and valid reasoning behind it originally, as given by the pxWidth example.

However, if one uses that system to distinguish an integer from a string etc. in a language with strong typing, then one simply hasn't understood how the language works.
The compiler will make sure you don't accidentially use an incompatible variable type. It simply isn't possible to confuse types (except for implicit conversions which are legitimate) if you care to hit the compile button before checking in your source (and if you don't verify that your code compiles before checking in, you'll probably get fired, anyway). Plus, modern IDEs figure out types even while you type, so you usually don't even need to go through the compile cycle to spot possible errors, the compile is only the last assertion that everything is correct.
Thus, there is no real benefit in making variable names less readable. A variable name (like all code) should be descriptive so one can understand the code, no more, no less. If some notation can convey useful and important information, that is fine. However, if it only copies something the language already does, it is just noise.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!