
|
ASP Naming Conventions By Nannette Thacker - 05/01/1999 Whether working on a development team or developing your own personal applications, it is good to develop and follow a set of naming conventions. Unfortunately, learning the value of good naming conventions is something recent to me. I've learned the hard way and still have hundreds of pages of code which were developed prior to realizing the necessity for such a standard. Following are my personal preferences. When setting technical integrity standards with a group, I prefer having the entire team hash out their preferences and developing a team standard and style. That ensures that the style will be followed, rather than ignored. Variable Names In Active Server Pages (ASP), all variables -- whether used as strings, dates, or numbers -- are of the variant data type. Many people dislike the variant datatype, but a lot of manual type conversion can be done away with. The secret to keeping track of the intended data type, especially if you are later saving your values to a database table, is in using proper naming conventions. In naming variables, the developer should be internally consistent. I prefer using a prefix before the variable name, which allows me to immediately identify the intended type. For instance, if I name all of my string variables with the "Str" prefix, I can easily view my source code and identify the type. I can also easily do a search on all "Str" variables by searching for "Str." Some developers simply use an "s" prefix for string, or an "i" prefix for "integer." However, for searching purposes, I prefer using the longer version. This naming standard also helps to avoid creating bugs caused by type confusion and makes it easier to find these bugs later.
Humpback Notation Use humpback notation on words within the variable name -- initial cap each word, with the remainder in lower case. I.E.: StrCompany, StrLName, IntAccountID. Some teams may decide to have the prefix in all lower case: strCompany, strLName, intAccountID. Neither way is better than the other. It is just a matter of team preference. Whatever is decided, it is important to follow the team's standard. Singular Names Only Another concern is the use of plurals in naming conventions. When programming, you may be trying to remember, is the name "StrStudents" or "StrStudent"? Many books are written recommending that variable, table, subroutines, and field names only be written using singular names to avoid this problem. It may save you a lot of time later in going back to look up the original name or debugging a "not found" error message. (I, personally, prefer the plural name for database tables, such as "accounts," "students," et cetera. However, because the majority of the world prefers the other, I have decided to be a team player, and henceforth, any new development I do uses the singular preference.) Dim Variables Dim variables when creating a new variable. Declare it first by using "Dim":
Dim strFirstName, strLastName To force yourself into this habit, declare Option Explicit at the top of every page. Review my article on Using Templates With Your ASP Development for more information on how to do this painlessly.
<% Option Explicit %>HTML Naming Conventions For information, please see our article on HTML Naming Conventions & Visual Interdev HTML Generation.
|
|
