Where to use what convention?
This is where the Hungarian Naming Convention developed by a great
Hungarian developer called Charles Simonyi who led Microsoft's
development team in the afx days while the Microsoft Foundation Classes
library was implemented. MFC is still in use to this day, though
abstracted by layers like the .NET framework.
You will see where camelCase can be used, and where UPPERCASE can be
used. Everything else is PascalNamingConvention. This rule of thumb
will take you far (until we get to Hungarian that is).
camelCase convention Should be used only for local method variables,
private variables, event handlers and catch blocks.
MyMethod()
{
try
{
int nVariable;
Button objButton = new Button();
objButton.Click += myButtonClickHandler;
…
}
catch(Exception ex) // or catch(Exception objException)
{
throw new Exception(“[MyMethod()] “ +
ex.Message);
}
}
public class MyClass
{
private int _nCounter=0;
}
Note that private members in a class should always begin with an
underscore. This is extremely _important. This will make your accessors
and mutators (properties:get/set) easier to read.
UPPERCASE Convention Should only be used for constants and enumerated
values.
const int PI=3.14159;
enum MyPossibleStates
{
UNKNOWN=0,
SLEEPING=1,
RUNNING=2,
AWAKE=3
}
(or)
enum MyPossibleStates
{
UNKNOWN,
SLEEPING,
RUNNING,
AWAKE
}
NOTE: Uppercase can also be used for abbreviations within Pascal. For
example: System.Web.UI or System.IO.
The PascalNamingConvention is Used for NameSpaces, Classes, Method
Arguments, Method Declarations, class members, method names, etc.
Everywhere that camelCase or UPPERCASE cannot be used. Simple Rule of
thumb.