views:

216

answers:

4

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?

+3  A: 

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.

sipwiz
+1  A: 

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.

JD
+1  A: 

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 a bitch to read, use, maintain and port. If they have 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 which retard 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'.

Wouter van Nifterick
I think case-sensitivity wasn't so much invented as simply done by default, since it's computationally a little cheaper (at least on an ASCII system). I have the impression that more recent and higher-level languages are more likely to be case-insensitive for identifiers.
cheduardo
Yeah, it's alightly easier to compare if characters are exactly equal. Don't even get me started about unicode source code.. It's a bitch to read, and I don't even know how to type most of the characters.
Wouter van Nifterick
+2  A: 

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

smcameron