
Naming Conventions (pascal, camel, etc)
Hello Michael,
Quote:
> 1. Hungarian notation - Microsoft's Capitalization Styles suggests
using
> Pascal case for static fields, but their Static Field Naming
Guidelines
> section suggests using Pascal case WITH Hungarian notation. Which is
more
> correct or more accepted?
I read that hungarian notation (and/or derivates) should not be used any
more. No "CPerson" and "strValue" any more...
Replace static fields with property definitions, use Pascal case in this
case ("FileName", "EndDate", etc.).
Quote:
> 2. Underscores for static fields - our team is considering adding an
> underscore in front of Static field names. The intention would be to
easily
> denote which variables are within class-level scope. MS's guidelines
make
> no mention of using underscores. I have seen underscores and Camel
case for
> static fields before. MS's guidelines strictly suggest using Pascal
case
> for static fields.
We use "m_" in combination with a type prefix (not required but nice)
for private member variables and Pascal case for the variable name, e.g.
"m_strUserName".
General rule: No prefix (except "I" for Interfaces), type prefix, and
Camel case for elements which are part of the object interface. Local
variables can use Camel case (*ugly*).
Quote:
> 3. Identification of controls - if not using Hungarian notation, it
would be
> nice to be able to identify control types in static field names. I
haven't
> seen any recommendation on this. Example: I have a form with a Label
> control and a TextBox control. The Label's text is "First Name:" and
the
> textbox is used by the user to enter their first name. To me, it
would make
> sense to name these controls FirstNameLabel and FirstNameTextBox. Or
if
In my opinition this doesn't make any sense. If you create a class that
derives from a control (e.g. TextBox, it can be called
"ExtendedTextBox", a class extending Form will be called "MainForm",
"SetupForm", and so on).
When writing code you often don't know the control's exact name. When
naming controls with a type prefix ("lbl", "txt", etc.) it's easier to
locate them in the intellisense box (you type "lbl" and see all label
controls grouped).
Quote:
> using the underscore: _firstNameLabel and _firstNameTextBox. My
problem
> with using this convention is that long control names take more time
to type
> (e.g. _stateDropDownList). Hungarian notation would shorten these
names up
> quite a bit: lblFirstName, txtFirstName, drpState.
IMHO this is the better convention.
Quote:
> Any suggestions? My goal is to adopt a convention that is intuitive,
easy
> to read, and easy to understand. A smaller goal is to conform to
other
> practices in the developer community.
;-)
Regards,
Herfried K. Wagner