Search code examples
naming-conventionsfxcophungarian-notation

Naming advice for replacing/avoiding hungarian notation in UI?


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?


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.