Tips_namingconventions   >   Variable Names

Variable Names

The following are some general guidelines for variable names:

Task Variables

Try to limit the use of task variables. In object-oriented programming you always use the lowest possible scope for each variable. I normally only use task variables to instantiate object classes which need application wide scope.

Task variables are all lower case and usually a shortened name of the object class they point to. The task variable names are misspelled on purpose so that Find & Replace can be used to find all occurrences of a specific task variable in the code.

The following are examples of startup task task variables:

Shorter task variable names look cleaner in the code.

Do fn.$retAlphaNumeric(String) Returns Value

Class Variables

Generally it is best object-oriented programming practice to avoid the use of class variables.

One situation where I always use class variables is input variables for prompts. The user might be running a series of reports and I need to prompt them for the date range of records to include in the report. In that situation I will use the class variables cDateFrom and cDateTo, so that the next time the user is prompted, the last dates they entered will be prefilled with the last dates they entered. (For as long as they have the application open.)

Class variables are prefixed with lower case c.

cVarName is a class variable.

Instance Variables

Use instance variable for any values that need to be visible to all of the methods within a class instance.

Instance variables are prefixed with lower case i.

iVarName is an instance variable.

Local Variables

Local variables are only visible within the method they are declared. Good OO practice uses the lowest scope variable needed. If you can use a local variable, do so. As soon as the method is finished the local value is cleared.

Local variables are not prefixed.

VarName is a local variable.

Parameter Variables

Parameters are a type of local variable.

Parameter variables are prefixed with lower case p.

pVarName is a parameter variable.

Parameter naming conventions are especially important since the parameter names are automatically copied to the Do statement when you drag a public method from the Interface Manager. For that reason, there are a few additional naming conventions for parameters.

List Variables

If there is an instance variable list or row in a class or superclass that could be defined differently for various instances of that class the names, iList or iRow are used.

If there are more list variables the variables are named to clarify what the data they contain. (iVendorsList, BooksList, AuthorsList).

Note that the plural form of the word is used for the list variable name. (VendorsList not VendorList)

Row variables follow the same naming convention as lists except that they use the singular form of the word. (VendorRow)

At one time I would always use the generic local variable names List or Row in short methods where I felt it was clear enough what the data the list or row variable contained. Since then I changed my practice to using list or row variable names which clearly communicate the data the list or row variable contains.

Tip

A coding practice I sometime use is to start with the local variable names List or Row when I write the method and then rename the variable when I finish the code. For example, List is renamed to VendorsList. Omnis kindly changes all occurrances of List to VendorsList for me.

Standard Variable Names

The following are standard variable names:

Variable Prefixes

The following are standard variable name prefixes.

See Parameter Variables for the special parameter prefixes.

Variable Suffixes

The following are standard variable name suffixes: