Question

I've stopped using Hungarian notation everywhere except in the UI, where often I have a username label, a user name text box, a user name local variable, a required field validator, a user name property and method parameter so on, often all in the same context.

current: lblUser, txtUser, rfvUser, _User, User, user

If I do the obvious, UserLabel, UserTextBox, UserRequiredFieldValidator, it seems like I'm just substiuting longer suffixes for shorter prefixes.

And the _ for indicating field, gets flagged by FxCop, but without a prefix, it would clash with the approved User/user convention.

Any suggestions?

Was it helpful?

Solution

I still generally use Hungarian notation for UI objects as I find it makes my code more readable.

I would use things like m_firstNameTextBox or m_countryComboBox for the UI controls and then m_firstName and m_country for the string values from those controls.

At the end of the day you should use whatever you prefer. The blanket rule to avoid Hungarian notation is as bad as the one that stipulates religous use of it. It's obivous that things like intCounter, strName are overkill but in other cases it does make good sense to indicate the type of class in the variable name and in my opinion UI controls happens to be one of the cases where it does make sense.

OTHER TIPS

There is nothing wrong with Hungarian notation, as long as it's used to make code more readable. If you think it doesn't contribute to that, then don't use it.

Ah, and please do not use both 'User' and 'user'. It's difficult to read, use, maintain and port. If two different things have two different meanings, then Hungarian notation is a better option than encoding that piece of information by flipping characters between uppercase/lowercase.

I don't know who invented case-sensitivity in program languages, but he did more damage than anyone could've imagined at the time. I hate getting compiler errors because I typed 'ID' instead of 'Id' or 'UsbDrive' when it should've been 'USBDrive'.

I prefer Hungarian even though it leads to really long names in the UI (because of problem you mentioned in question). My only suggestion is to be consistent across the entire team.

Use all lowercase and underscores, and the case issue goes away. SomeIdiotSomewhereDecidedThisWasAGoodWayToDoThingsAndIfIFindHimIWillKillHim.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top