Using Standard Naming Conventions in Visual Studio NETChanged Again | | What naming conventions should I use in naming variables, classes, Namespaces, etc? Microsoft has once again redefined the standard naming conventions with the advent of .NET.
Instead of being critical of Microsoft, which I am not doing, this article is being written simply to point out that Naming Conventions that we have used in the past, and many of which we learned from Microsoft, have once again been redefined.
Before Strict Typing was enforced, or even necessarily encouraged in Visual Basic, Microsoft and others were suggesting, if not pushing, certain standards for variable names, classes, Forms, and Control names. Not only did we name the variable, but we also indicated Scope and Type as part of the variable name. Take a look at some of the following examples:
Depending on how fond of or how good you were at typing, you would use
Dim strLastName As String
Dim intPageCounter As Integer
Dim dblCurrentValue As Double
|
or
Dim sLastName As String
Dim iPageCounter As Integer
Dim dCurrentValue As Double
|
If you were really into specifics, you may have indicated the Scope of the variable in its name as shown below. The first character "l" indicates a Local or procedure level variable.
Dim lsLastName As String
Dim liPageCounter As Integer
Dim ldCurrentValue As Double
|
We also may have delineated between Local and Module Level variables (Scope) by using something like the following, where the "m" denoted a Module Level variable, and "lng' identified the variable as a Long.
Private mlngLineCount As Long
|
If you happend to have been around PowerBuilder programmer, and even some Microsoft folks, you probably have run into this variation.
Private m_lngLineCount As Long
|
But, with the advent of Visual Studio .NET, Microsoft has published new guidelines for Naming Conventions. However, they are suggesting some choices that are acceptable.
For variable names, you can use Pascal Case or Camel Case, as in the following examples:
Pascal
Camel
You will note that neither the Type nor the Scope is indicated by the above variables.
The intent of this article is not to give a complete explanation of the newly suggested Naming Conventions, but rather to introduce you to the fact that there are some. To see Microsoft's full discussion of this subject click on this Naming Guidelines Link.
There is also a Free tool, FXCop, introduced on GotDotNet that will examine your projects for conformance to these standards.
|