Variable and Constant Naming Conventions

The names that you give to your variables will not have that much impact on how your application runs on the user's workstation, but it can affect the clarity of the source code. In the days before .NET, many Windows programming languages used a system called Hungarian Notation to craft variable names. Such names helped to communicate information about the data type and usage of a variable to anyone reading the source code. Unfortunately, the rules used to define Hungarian variable names were somewhat complex, and varied not only between programming languages, but between programmers using the same language.

When Microsoft released .NET back in 2002, its documentation included various programming recommendations. One of those recommendations was, "Stop using the Java programming language." Another recommendation encouraged programmers to cease from using Hungarian Notation, and instead embrace a new system that used casing rules to differentiate variables. The rules state that all variable names should employ mixed-case names (where each logical word in the variable name starts with a capital letter and continues with lowercase letters). The only differentiation comes in the capitalization of the initial letter.

  • Set the first letter of all local variables and all method parameters to lowercase. This is known as Camel Casing.

  • Set the first letter of all fields, methods, type members (including controls), and types to uppercase. This is known as Pascal Casing.

In the interest of full disclosure, I must tell you that I modified the original recommendations slightly from the documentation supplied with Visual Studio. The original rules were a little more complex when it came to field and method parameter names. Personally, I find the two rules listed here to be adequate for my needs.

You might give a local variable a name like lookInThisVariable, which capitalizes the first letter of each word, but not the initial letter. If you defined this variable as a field instead, you would change its name to LookInThisVariable, capitalizing the first letter.

Start-to-Finish Visual Basic 2005. Learn Visual Basic 2005 as You Design and Develop a Complete Application
Start-to-Finish Visual Basic 2005: Learn Visual Basic 2005 as You Design and Develop a Complete Application
ISBN: 0321398009
EAN: 2147483647
Year: 2006
Pages: 247
Authors: Tim Patrick

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: