Variables

The names of variables should document their meaning or use.

Variable names should be in mixed case starting with lower case

This is common practice in the C++ development community. MathWorks sometimes starts variable names with upper case, but that usage is commonly reserved for types or structures in other languages.

linearity, credibleThreat, qualityOfLife

An alternative technique is to use underscore to separate parts of a compound variable name. This technique, although readable, is not commonly used for variable names in other languages. Another consideration for using underscore in variable names in legends is that the Tex interpreter in MATLAB will read underscore as a switch to subscript.

Variables with a large scope should have meaningful names; variables with a small scope can have short names

In practice most variables should have meaningful names. The use of short names should be reserved for conditions where they clarify the structure of the statements. Scratch variables used for temporary storage or indices can be kept short. A programmer reading such variables should be able to assume that its value is not used outside a few lines of code. Common scratch variables for integers are i, j, k, m, n and for doubles x, y and z. For applications with complex numbers, i and j should be reserved.

The prefix n should be used for variables representing the number of objects

This notation is taken from mathematics where it is an established convention for indicating the number of objects.

nFiles, nSegments

A MATLAB-specific addition is the use of m for number of rows (based on matrix notation), as in mRows.

A convention on pluralization should be followed consistently

A suggested practice is to make all variable names either singular or plural. Having two variables with names differing only by a final letter s should be avoided. An acceptable alternative for the plural is to use the suffix Array.

point, pointArray

Variables representing a single entity number can be suffixed by No or prefixed by i

The No notation is taken from mathematics where it is an established convention for indicating an entity number.

tableNo, employeeNo

The i prefix effectively makes the variables named iterators.

iTable, iEmployee

Iterator variables should be named or prefixed with i, j, k etc.

The notation is taken from mathematics where it is an established convention for indicating iterators.

for iFile = 1:nFiles
    :
end

Note that applications using complex numbers should reserve i, j or both for use as the imaginary number. For nested loops the iterator variables should be in alphabetical order. For nested loops the iterator variables should be helpful names.

for iFile = 1:nFiles
    for jPosition = 1:nPositions
        :
    end
    :
end

Negated boolean variable names should be avoided

A problem arises when such a name is used in conjunction with the logical negation operator as this results in a double negative. It is not immediately apparent what ~isNotFound means.

Use isFound

Avoid isNotFound

Acronyms, even if normally uppercase, should be mixed or lower case

Using all uppercase for the base name will give conflicts with the naming conventions given above. A variable of this type would have to be named dVD, hTML etc. which obviously is not very readable. When the name is connected to another, the readability is seriously reduced; the word following the abbreviation does not stand out as it should.

Use html, isUsaSpecific, checkTiffFormat()

Avoid hTML, isUSASpecific, checkTIFFFormat()

Avoid using a keyword or special value name for a variable name

MATLAB can produce cryptic error messages or strange results if any of its reserved words or built-in special values is redefined. Reserved words are listed by the command iskeyword. Special values are listed in the documentation.