Author Topic: Avoid Hungarian Notation  (Read 6228 times)

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Avoid Hungarian Notation
« on: August 18, 2013, 09:21:19 AM »
Many developers continue to use a practice known as Hungarian notation for naming variables. Hungarian notation uses a lower case prefix to indicate the type of the variable, for instance "blnLight" indicates the variable is a Boolean type.

When developing in .NET, Hungarian notation is no longer consider a pattern or best practice. Here is a link to Microsoft's page listing preferred naming conventions:

http://msdn.microsoft.com/en-us/library/ms229045.aspx

dmroeder

  • Administrator
  • Full Member
  • *****
  • Posts: 212
    • View Profile
Re: Avoid Hungarian Notation
« Reply #1 on: October 11, 2013, 06:48:18 PM »
(I realize this is old)

I got in that habit from a VB6 book I read some time ago and it's been hard to break.  I went back to modify an old program I did some time ago and it was all over.  At one point I did a little Java and lately a little C++ and I could see that Hungarian notation is never found in any examples I see from those languages.  I've since moved away from it.

dmroeder

  • Administrator
  • Full Member
  • *****
  • Posts: 212
    • View Profile
Re: Avoid Hungarian Notation
« Reply #2 on: November 12, 2013, 10:46:24 AM »
A friend of mine sent me an interesting read that I thought I'd share on this subject:

http://www.joelonsoftware.com/articles/Wrong.html

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Avoid Hungarian Notation
« Reply #3 on: November 15, 2013, 07:31:00 AM »
The article has an interesting history on Hungarian notation that I did not know.

When I first learned about "Avoid Hungarian Notation" in .NET, it's justification was that Visual Studio tells you the type by hovering the mouse over. But my first thought was "what about when you view code in something like Notepad? How do you quickly recognize the variable type?"

But I figured since it came from the mouth of the .NET system creators, they must know best.


dmroeder

  • Administrator
  • Full Member
  • *****
  • Posts: 212
    • View Profile
Re: Avoid Hungarian Notation
« Reply #4 on: November 15, 2013, 09:43:31 AM »
I've been branching out a bit into Java and C++ in Eclipse (Linux) and it's not as fancy as Visual Studio in that it doesn't do any of the auto-complete, help you correct syntax or show you variable types when hovering so I find myself falling back on using Hungarian notation. 

Java seems to be picky about things that were simple in VB.NET like if you try to multiply an integer and a float data type.  Java wants them to be the same type.  You don't find out until you try to run your program, which meant that I compiled it and transferred it to my phone.  Then crap, it just crashed and now I need to find out why.  I had been using what he was calling Apps Hungarian style to make sure that my data types were like when doing any math so that I would avoid the mistake.