views:

78

answers:

3

I totally agree that we should not use Hungarian Notation to name variables. But it seems that Hungarian Notation is still useful to name controls (especially Winform controls). Consider these:

GridView grvUsers
TextBox txtPassword

etc...

I really doubt that should we avoid Hungarian notation in this case? If should, which is alternative solution to name controls?

A: 

Obligatory Joel on Software blog link in 3... 2... 1...

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

Matt Ball
+1  A: 

I usually name controls according to what they are, but with more Englishy names. Like, i'll name a label control for a first name box, "FirstNameLabel", and the textbox "FirstNameBox". It wasn't even intentional; i just noticed one day i was doing it, and it made sense to keep doing it.

I think i'm gonna call this "American notation".

cHao
Same here, but lower case first character because these are private fields.
Pieter
A: 

Regardless of whether it is right or wrong, it is still the defacto standard to use Hungarian Notation for naming controls, and it seems very out-of-place not to adopt it. In the same way that methods in .NET languages use Pascal Casing (while in most other languages it is frowned upon), stepping outside of the accepted conventions for the environment you're working in just tends to make your code look even more out-of-place.

I am personally in favour of the practise, as it helps to distinguish class members which are part of the user-interface (view) from those members which are part of the code-behind (model/controller). If the control variables are given similar-looking names to those used to store data, state, etc then I feel as though it is harder to resist the temptation to tightly couple the two. Of course, a more distinct separation of logic would overcome that as well.

Nevertheless, Hungarian Notation leaves no doubt as to which variables are part of the user-interface, and also makes clear as to their type and function, both in the designer and the code editor.

Bradley Smith
Never mind that MS has said "don't do it". Never mind that every useful IDE in existence now can tell you the type of a variable just by you mousing over its name. Never mind that *you can't freaking read the names aloud without it being awkward.* Never mind that Hungarian notation should be describing the *kind* of stuff, not the class. Never mind that if you change that textbox to a rich text editor later, *your variable names are lying to you.* No, this practice *needs* to die.
cHao