To read the article online, visit http://www.4GuysFromRolla.com/webtech/top10/beg5.shtml

Use prefix notation when naming your variables!


  • Back to Beginner's Tip Index
  • Next tip...

    If you give your variables names like i, j, x1, stuff, or blah, you are using poorly named variables, I assure you! Imagine reading through the code. You come across a statement like:

    x1 = 5

    Now what does that mean? x1 = 5? What is the coder trying to do? (This is particularly embarassing when you are reading your own code sometime later!)

    First off, you should choose variable names that make sense. If the variable is going to store the user's name, it should be named strName, not a or something nondescriptive. Also, you should use prefixes to convey the type of data you expect to be stored in these variables. Below is a short table of prefixes commonly used for various types of variables. Since all variables are variants in ASP, there is no formal or explicit type casting. (Although you can use casting functions such as CInt(), CStr(), etc.)

    Prefix Notation
    Integeri
    Longlng
    Singlesgl
    Doubledbl
    Stringstr
    Booleanbol
    Objectobj

    I strongly suggest you adopt this naming convention, or use your own. Regardless of the standard you choose, what is important is that you adhere to it! :) You'll note that the majority of code snippets on the site that I have written use the above prefix notation.

  • Back to Beginner's Tip Index
  • Next tip...


  • Article Information
    Article Title: ASP Tips: Use prefix notation when naming your variables!
    Article Author: Scott Mitchell
    Article URL: http://www.4GuysFromRolla.com/webtech/top10/beg5.shtml


    Copyright 2017 QuinStreet Inc. All Rights Reserved.
    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers