Naming variables
 
 
 

Use descriptive variable names

To keep your MEL script clear and understandable to yourself and future users, use a variable name that describes the variable’s function.

Variable names such as x, i, and thomas are not as informative as carIndex, timeLeft, and wingTipBend. However, do not be too verbose. For example, indexForMyNameArray, is overly descriptive. Be clear, descriptive, and terse.

Avoid global variables

Global variables are dangerous to use for the exact reason that people use them: they are visible outside of the specific procedures and MEL scripts where they were declared. This visibility also makes them susceptible to being modified by any other MEL script that tries to use a global variable with the same name. This can create a problem that can be very difficult to find.

Example

proc int checkVisibility(int $value)
{
 global int $myIndex = 0;
 $myIndex = $myIndex + $value;
 return $myIndex;
}
proc iSeeYou()
{
 global int $myIndex = 0;
 int $value = checkVisibility(1);
 $myIndex = $myIndex + $value;
 print($myIndex);
}
iSeeYou; // Result is 2.

When the procedure iSeeYou is executed, the myIndex global variable becomes 2. This is because both procedures increment myIndex.

However, when you need to use a global variable, create a unique name so you do not overwrite the data of an existing global variable. You should also avoid global variables in procedures.