It's a generally considered a bad practice to use the Hungarian notation, but is common to find GUI controls named
Do you put the control type in it's name? Isn't this a kind of Hungarian notation?
Software Engineering Stack Exchange is a question and answer site for professionals, academics, and students working within the systems development life cycle. It only takes a minute to sign up.Sign up to join this community
Like you say. In general, Hungarian notation is a bad practice. I like to keep my names as close to the domain as possible, but sometimes what you are trying to say is that this is the textbox and this is the label.
See Kramii's answer to another question for his very reasonable take on why he still uses Hungarian in certain situations.
As with all code, consistency and self evaluation is key. If you and your team agree on how different GUI-controls are labeled, and what elements need labels, you'll be fine :)
Actually I use Hungarian notation, only for GUI controls. I use something like lblText, rbGroup1, lvTable etc for labels, radio buttons and list views.
They never tend to change anyway and it's clear what variable is a GUI control and what is not.
However, since I use WPF with binding possibilities it is not really necessary anymore to name them at all, since it is binded to a C# property.
Btw, don't make the mistake to call a control lvListViewPersons what I occasionaly see. If a variable is prefixed with lv you can see it is a listview already.
Our team is using Hungarian notation for GUI controls, not for the rest of the code.
Typical example, a label followed by a textbox:
Plus it makes it easy to find your textbox, just type "txt" and intellisense will do the rest.
I am using Hungarian notation for GUI elements. It really is the pain when you close QtDesigner, open Visual Studio and when you want to set text on button if you have textbox named
password, etc. When you use Qt, it is not big problem, because all GUI elements are wrapped inside
ui object (
ui.username), but when I use Windows Forms, textbox named username only bloats namespace.
In that case,
lblStatus, etc. are clearly better options.
I avoid using hungarian notation for GUI controls - I would avoid naming a control like `lblFirstName' because I don't really care that it's a label - from a data binding point of view it's just something to bind.
For controls that need a name I usually add the prefix
ux for 'user experience'. That makes it clear that the item is intended only for the user to interact with. For example my view model might have a property called
FirstName and the view might have a control called
uxFirstName. This has the added benefit that all of my named controls are nicely grouped in my IDE.
I know people can't stand Hungarian notation overall, but I still find it very useful in a lot of places. For GUI I use wnd prefix at least.
The problem of not using Hungarian notation is simple, once you leave the smooth waters of MSVS, the navigation takes a nose dive. You see some sort of
SomeValue = SomeOtherValue and you have no clue what is going on unless you look up every damn thing. Via grep or good old search, that usually kills the productivity right there, IDEs other than QT and MSVS are really bad at lookups.