Rules of naming variables





This article describes the standards that apply to variable names. All of the listed recommendations are mandatory unless noted otherwise.

1. Name your variables based on the terms of the subject area, so that the variable name clearly describes its purpose.

2. Create variable names by deleting spaces that separate the words. Capitalize each word in the name, including prepositions and pronouns that consist of a single letter.

Example:

Variable DirectoryProcessingDialog; // Dialog to work with a directory
Variable PacksInBoxQuantity; // Number of packs in a box

Examples of incorrect variable names:

maxAttributes, matchTypeName, newStr

3. Do not begin variable names with an underscore.

4. Do not use variable names that consist of a single character. Short variable names are only allowed for loop counters.

5. Name variables that describe binary states ("true" or "false") after the state that matches the "true" value.

Example:

Variable HasErrors; // Shows whether procedure contains errors.
Variable IsReusableContainer; // Shows whether a product is a reusable container.

See also:


Comments
0
Add comment