wood burning stoves 2.0
The moose likes Cattle Drive and the fly likes Hungarian Notation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Hungarian Notation" Watch "Hungarian Notation" New topic

Hungarian Notation

Nick White
Ranch Hand

Joined: Oct 09, 2006
Posts: 94
Whilst attempting DaysOld OOP1 assignment I was nitpicked with the following comment:

This seems a lot like Hungarian notation (which is forbidden)

Perhaps someone could explain to me what is Hungarian Notation, and why is it forbidden?


Nathan Leniz
Ranch Hand

Joined: Nov 26, 2006
Posts: 132
I got the same nitpick on a different assignment. I did some searching and came up with this.

It explain it really well, but in short it means the name of an object indicates its type or intended use.

int iVar
String sName
Banana bMyBanana

And reasons not to use it include:

*It encourages the use of poor naming practices. For example it becomes confusing when it is used to represent several properties, as in:

a_crszkvc30LastNameCol : constant reference function argument, holding contents of a database column of type varchar(30) called LastName that was part of the table's primary key

* It is inconsistent with code portability since the variable name is tied to the type. A particularly well known example is the standard WPARAM type, and the accompanying wParam formal parameter in many Windows system function declarations. It was originally a 16 bit type, but was changed to a 32 bit or 64 bit type in later versions of the operating system while retaining its original name (its true underlying type is UINT_PTR, that is, an unsigned integer large enough to hold a pointer).
* It dramatically reduces readability for those unfamiliar with the notation
* Modern Integrated development environments will automatically flag operations which use incompatible types, and display variable types on demand; making the notation obsolete.
* It may lead to inconsistency when code is modified. If a variable's type is changed, its name may reflect the previous type, leading to confusion.

The very existence of flamethrowers proves that at some time, some where, some place, someone once said to themselves "I'd really like to set those people on fire over there, but I just can't get close enough".
Pauline McNamara

Joined: Jan 19, 2001
Posts: 4012
Here's a succinct explanation of Hungarian Notation in the Style Guide.

What? Haven't memorized the Style Guide yet?
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
I recommend this article by Joel Spolsky, which is also linked in the Wikipedia. It's more fun to read, and may be sufficient as an introduction.
Nick White
Ranch Hand

Joined: Oct 09, 2006
Posts: 94
Thank-you all for your replies.

Pauline, I have never mastered anything to do with style, even with a guide.
I agree. Here's the link: http://aspose.com/file-tools
subject: Hungarian Notation
It's not a secret anymore!