Script writing guidelines, Coding guidelines, Style suggestions – Visara Master Console Center Scripting Guide User Manual
Page 22: Coding guidelines style suggestions

Chapter 2 Advanced Topics
Scripting Guide
22
Script Writing Guidelines
The following coding guidelines and style suggestions increase code
readability and ease maintenance:
Coding Guidelines
End all scripts with RETURN, so they can be easily called from other
scripts.
Always check return values.
Use SCANP whenever possible, not SCANB.
Avoid using GOTOs, except with functions such as SCANP.
If a section of code is repeated, make it a subroutine.
Initialize variables before use.
Plan the script to ensure there are paths for each possible condition,
and avoid “fall-through” situations. For example, if a RETURN is not
specified, control of the script may fall through to the next subroutine
by default, and not be processed correctly.
Use Manifest Constants (see page 42), not values. For example,
TRUE|FALSE is preferred to 0|1.
SWITCH-ENDSWITCH statements should always have a DEFAULT:
condition to handle unexpected values.
Style Suggestions
Keep subroutines as brief and as simple as possible. If a subroutine
exceeds 100 lines, consider breaking it into several subroutines.
Precede all scripts or subroutines with a description, including pre-
and post-conditions as well as exceptions and return codes that may
be passed.
Use variables in place of literals wherever possible.
Comment at each gosub call, stating the reason for each call if it is not
obvious.
Include a commented usage statement for each subroutine if it is not
obvious.
Do not comment obvious statements, for example, “%Continue
:=FALSE //don’t continue”.
Try to use the same case for variable names throughout a script.
Indent statements within control loops (IF-ENDIF, WHILE-
ENDWHILE...).
Put one space after each open parenthesis, and also after each comma.
This allows use of the Ctrl-Left Arrow and Ctrl-Right Arrow keys to
jump to the next word.