Writing Readable Code

An mvBASIC program should be made relatively easy to read, both for the programmer and for those who must maintain the program. The readability of a program can be greatly enhanced by:

When blank spaces or lines that are not part of a data item appear in a program line, they are ignored. Therefore, blanks can be used freely in order to improve the appearance and readability of a program. The programmer can use blanks to indent sections of code and make the program structure more apparent. Blank lines can also be used to set apart a subroutine or any other significant part of the program.

The programmer should make a habit of assigning recognizable names to variables and constants. It becomes much easier to keep track of what the variable signifies if variable names are kept coherent—for example, an array containing customer names and addresses would be easier to identify if it were called CUSTOMERS rather than X.

Using Remarks

Program documentation includes comments in the mvBASIC program that explain or identify various parts of the program. Comments are part of the source code only (the original program), and as such they are not executable. They do not substantially affect the size of the object code.

Comments must begin with one of these symbols:

REM

*

!

To place a comment on the same physical line as another statement, the first statement must first be ended with a semicolon (;), as in this example:

IF 2INT_SUM < 0 THEN

LOSS =2INT_SUM ;  *CORRECTLY FORMATTED COMMENT

END ELSE PROFIT = 2INT_SUM

Comments cannot be placed between multiple statements on one physical line. For example, in the second line of the following example all the text following the * symbol is treated as part of the comment and is not executed:

IF 2INT_SUM < 0 THEN

LOSS= 2INT_SUM ;  *THE REST OF THIS LINE IS IGNORED ;

END ELSE

Comments can, however, be placed in the middle of a statement that occupies more than one physical line, as in this example:

IF 2INT_SUM < 0 THEN

LOSS = 2INT_SUM

* THIS COMMENT IS ON A LINE OF ITS OWN

END ELSE PROFIT = 2INT_SUM

Remarks in the Object Code

A special form of comment can be used to embed a comment directly into the object code. A statement beginning with $* places the following text into the object code created when the program is compiled. For example:

$* "OPERATING SYSTEM VERSION 2.5"

Comments in the object code are particularly useful for including the version number of the program, or for entering copyright information.

See Also

Program Format

Types of Statements

Statement Labels