12

It's a generally considered a bad practice to use the Hungarian notation, but is common to find GUI controls named userNameTextBox and userNameLabel.

Do you put the control type in it's name? Isn't this a kind of Hungarian notation?

  • on the whole mine don't have names as they don't need them in WPF – jk. Jun 11 '12 at 18:21
12

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 :)

8

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.

  • 3
    Agree with this. GUI controls are the only place where Hungarian notation isn't a cardinal sin (IMO of course) – Wayne Molina Jun 11 '12 at 11:21
4

Our team is using Hungarian notation for GUI controls, not for the rest of the code.

Typical example, a label followed by a textbox:

  • lblFirstName
  • txtFirstName

Plus it makes it easy to find your textbox, just type "txt" and intellisense will do the rest.

1

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 username, 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, txtUsername, btnLogin, lblStatus, etc. are clearly better options.

1

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.

  • 3
    Isn't the ux prefix itself Hungarian Notation? Maybe the other kind (I forget the names of the two) that indicates meaning and not type, but still a form of Hungarian ;-) – Wayne Molina Jun 11 '12 at 11:22
  • I think you're referring to apps hungarian as opposed to systems hungarian. Apps hungarian isn't considered nearly as harmful as systems, but I think the meaning of'ux' could be too high level to even be considered apps. I guess you could call it layer hungarian or something :) – MattDavey Jun 11 '12 at 14:14
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.