|
|

tips menu | printable single page versionNote: this
is my old ASP tips page and is no longer supported. See the new Visualize web site..
ASP Coding and Style - Variable Naming Conventions
Consistency is the key here. Variable naming conventions are usually left to the developer, and each will have their own preferences as to what "works for them" etc. However, from a team maintenance point of view, it is well worth adopting a standard within teams where possible. My personal preference is the hungarian style notation, which is well established and can be used across a number of languages. The big plus with this approach is that you can immediately tell the type of data that is being stored in each variable, just from seeing its name (rather than having to track down its declaration). As you are likely to be aware, ASP uses Variants and does not explicitly declare variables of particular types. Even though this is true, it is still extremely useful to know what is intended to be stored in the variable, and hence this notation is worth considering for ASP. Take it from me, once you get used to using this approach, it will become a very useful habit!
The notation adopts a lowercase prefix, indicating the data type of the variable concerned, followed by the name of the variable itself, often capitalising each word within it (no spaces). Constants are similar, but typically we only lowercase the prefix, capitalising the rest of the name to clearly distinguish these from normal variables. Below provide some typical examples:
| Variable Name | Data Type | Prefix |
| iPeopleCount | integer | i |
| bEndOfFile | boolean | b |
| sName | string | s |
| oMyObject | Object | o |
| rsMyRecordset | Recordset Object | rs |
| iFIXEDSIZE | integer constant | i |
Obviously, this list can be extended (e.g. col for collections, txt for HTML text boxes etc.), but I'll leave that to you.
DISCLAIMER: Note these pages are a free resource for anyone wishing to reference them. Although every care is taken to ensure their correctness, the author takes no responsibility for any errors or problems that may occur through their use, or indeed misuse. These pages are copyight of Dave Clarke, Visualize Software Ltd 1997-2000 (all rights reserved).
© Copyright
Dave Clarke, 1996-2010
|