• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hungarian Notation

 
Nick White
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Regards

Nick
 
Nathan Leniz
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a succinct explanation of Hungarian Notation in the Style Guide.

What? Haven't memorized the Style Guide yet?
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank-you all for your replies.

Pauline, I have never mastered anything to do with style, even with a guide.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic