Why NOT hungarian notation?

D

darrel

I just discovered that MS recommends that we NOT use hungarian notation with
the .net framework:

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

What are the real cons for using it?

I tend to use it a lot, especially when IDing my controls. For instance the
controls in a contact form I create could be IDed as such:

tbx_firstName
tbx_emailAddress
ddl_state

I find this really helpful when in codebehind.

is the 'no hungarian' merely a preference MS has, or are there specific cons
to me being stubborn and sticking with it?

-Darrel
 
M

Mark Rae

I just discovered that MS recommends that we NOT use hungarian notation
with the .net framework:

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

Weird, isn't it! It was all the rage for years, then suddenly they don't
like it any more...
What are the real cons for using it?

None whatever.
I tend to use it a lot, especially when IDing my controls.

Me too - all the time.
I find this really helpful when in codebehind.
Likewise.

is the 'no hungarian' merely a preference MS has,

I have no idea...
or are there specific cons to me being stubborn and sticking with it?

None whatever.
 
D

darrel

or are there specific cons to me being stubborn and sticking with it?
None whatever.

Ha! Thanks for the feedback, Mark. At least I can find peace with me knowing
that I'm not alone in wanting to stick with it. ;o)

-Darrel
 
K

Karl Seguin

The biggest argument against hungarian notation is that it makes it harder
to refactor code. People argue that it's violates the Don't Repeat Yourself
(DRY) principle. Personally, I think that's a little much, but the side
effect IS the same. If you change the type of your variable, you now need to
change all instances of that variable.

if you have rptBooks and want to change it to a datagrid, you now have to
refactor your name or risk having hard code to maintain.

With the advances in IDEs generally and intellisense specifically, the
question is what value does hungarian notation offer?

I'd be interested in taking a look at a codebehind page you feel it ads
value.

Karl
 
M

Mark Rae

Ha! Thanks for the feedback, Mark. At least I can find peace with me
knowing that I'm not alone in wanting to stick with it. ;o)

Without doubt the stupidest reason for not using it I've ever come across
was that you might change the underlying datatype (e.g. from byte to
integer) that a variable referred to, so you'd have to go through your
entire code and change it...

Well, my copy of VS.NET has got a find and replace utility...
 
M

Mark Rae

If you change the type of your variable, you now need to change all
instances of that variable.

Personally, I would use Find / Replace for such a task - wouldn't you...?
 
R

Registered User

I just discovered that MS recommends that we NOT use hungarian notation with
the .net framework:

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

What are the real cons for using it?
Nothing although the various 'dialects' can be confusing and
internally inconsistent.
I tend to use it a lot, especially when IDing my controls. For instance the
controls in a contact form I create could be IDed as such:

tbx_firstName
tbx_emailAddress
ddl_state

I find this really helpful when in codebehind.
My preference is to be verbose as needed to make the code easier to
read. A few extra key strokes for clarity can go a long a way i.e.
firstNameTextBox or firstNameEdit.
is the 'no hungarian' merely a preference MS has, or are there specific cons
to me being stubborn and sticking with it?
You may run into situations where corporate/department/office policy
does not appreciate hungarian notation as much as you do. For all
practical purposes IntelliSense and similar tools make hungarian
notation obsolete.

regards
A.G.
 
L

Laurent Bugnion

Hi,

Registered said:
You may run into situations where corporate/department/office policy
does not appreciate hungarian notation as much as you do. For all
practical purposes IntelliSense and similar tools make hungarian
notation obsolete.

regards
A.G.

Very much in the contrary IMHO. I tend to forget how my variables are
named, especially which letter they start with, but I do not forget
which type they have. If I want a string, I type "str" and all the
strings are nicely grouped in Intellisense. If anything, Intellisense
makes hungarian notation even more useful!!

HTH,
Laurent
 
M

Mark Rae

Very much in the contrary IMHO. I tend to forget how my variables are
named, especially which letter they start with, but I do not forget which
type they have. If I want a string, I type "str" and all the strings are
nicely grouped in Intellisense. If anything, Intellisense makes hungarian
notation even more useful!!

Tout à fait d'accord avec toi, mon pote!

Which is to say that I agree entirely with Laurent.

Hungarian notation makes it easier for me to write my applications - if I
didn't use it, it would make it more difficult for me to write my
applications.

I think the OP would also agree with the above...
 
D

darrel

If anything, Intellisense makes hungarian notation even more useful!!

Excellent point!

-Darrel
 
R

Rad [Visual C# MVP]

With the advances in IDEs generally and intellisense specifically, the
question is what value does hungarian notation offer?

So true! Especially as VS 2005 has very good refactoring that kicks in when
you rename a variable!
 
K

Karl Seguin

no.

find/replacing is dangerous. What happens if you use that same name
somewhere else but don't change its type?

I use JetBrains Resharper which provides much better refactoring than VS.NET
2005. It would do it for me. So that's a case against my own argument :)

Karl
 
R

Registered User

Very much in the contrary IMHO. I tend to forget how my variables are
named,

I would suggest using a more meaningful naming convention but I just
can't fathom the situation you describe.

regards
A.G.
 
M

Mark Rae

find/replacing is dangerous. What happens if you use that same name
somewhere else but don't change its type?

Then I would correct it on the unlikely event that that would occur...

Also, I wouldn't just blithely hit "Replace all"...
I use JetBrains Resharper which provides much better refactoring than
VS.NET 2005. It would do it for me. So that's a case against my own
argument :)

LOL! Well there you go!
 
J

Jay Pondy

I do use o for local objects, mo for class or module level and go for global
objects. Hungarian Notation rocks and after using it for the last 15 years I've
yet to see a good reason not to.
 
J

Jay Pondy

That is a very good article. I wish I had known about Apps Hungarian because
apparently I am an abuser of Apps System where the type is a small part of the
variable naming convention rather than the "kind" of thing it is.

When I see code that does not use Hungarian notation I feel like half my brain
is turned off and I then have to work twice as hard to stay in the same place.
Joel does an excellent job of explaining why and where that perception comes
from.

Thanks for a great perspective.
 
J

Joerg Jooss

Thus wrote Mark,
Without doubt the stupidest reason for not using it I've ever come
across was that you might change the underlying datatype (e.g. from
byte to integer) that a variable referred to, so you'd have to go
through your entire code and change it...

Well, my copy of VS.NET has got a find and replace utility...

Unfortunately, changing source code all over the place usually means going
through the entire test cycle of that component *again*, even though semantically
there's no change. Accordingly, changing a variable name because of a type
change is not only stupid but also expensive, IMNSHO.

Cheers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top