Programming conventions become extremely important in a team environment. If the code is easy to read, understand, and maintain, any programmer should easily and quickly be able to find what they need to know. Coding conventions can include:
- Standardized formats for labeling and commenting code.
- Naming conventions for objects, variables, and procedures.
- Guidelines for spacing, formatting, and indenting.
- Appropriate internal and external documentation for their software.
Internal Documentation
Comments are text added to code that explains how the code works. In Visual Basic, a comment line can start with either an apostrophe (') or with the Rem keyword followed by a space. The following will apply to all programs you write from now on:
- Every variable used will be commented.
- A line of stars or other characters will separate each procedure.
- Every procedure or function should have a brief description as to its purpose.
- In the general declarations of each form put your name, due date, program name and brief description. For example
- ‘*************************************************************
- ‘ Program : Phone book
- ‘ Due Date : place due date here
- ‘ Name : Your name
- ‘ Description : Program simulates a phone book using a drop down list box
- ‘**************************************************************
Coding Conventions
- White space improves readability, so indent all code inside loops and conditional statements. Use blank lines to improve readability.
- All objects should be named with a consistent prefix that makes it easy to identify the type of object (ie cmd for command buttons)
- All variables must be declared at the top of the procedure or form in which they are used, commented appropriately and use the standard naming prefix.