Touch Technologies, Inc.
Coding Standards


Previous Contents Index

RULE

IF THEN statements should not be nested. Avoid more than 3 levels of indentation (nested LOOPS and IFs, etc.) to keep the code in that routine from becoming too complex. If there are more, then an inner loop should be moved out to a new routine. Keeping the indentation to no more than 3 levels keeps the code looking neat, clean, and easy for the reader to follow.

REASON

Keeps coding easy to understand for later enhancements.

RULE

The block of code under loops and within routines must be indented two spaces under the beginning statement.

REASON

Makes code neater and easier to read. Also makes searches easier.

EXAMPLE

Example 1-27 Code Block Indentation

routine do_total 
  for i = 1 to 10 
    total(i) = 0 
  next i 
end routine 

See Section 5.11, Tab Key to Indent for instructions on how to easily adjust code indentation using a specially mapped keystroke in SPDEV.

RULE

Continuation lines (those that follow an & or + on the previous line) must be indented 4 spaces beyond the normal indentation level for that section of code.

REASON

Makes code neater and easier to read.

EXAMPLE

Example 1-28 Continuation Indentation

  if  (previous_line < include_line_nbr)  and & 
      (current_line  > include_line_nbr)  and & 
      (line_begin    = true)  then 
      print #report_ch: 'Total sales for this month = '; & 
          tot_sales 
  end if 

See Section 5.8, GOLD/F to Fixup Right Margin for instructions on how to fixup the right margins (word wrap) of your code using a specially mapped keystroke in SPDEV.

RULE

Avoid using ELSE in conditional constructs if a separate IF THEN statement will make future enhancements to the code simpler. For example, a program that is 25,000 lines of code (including comments) might have approximately 20 ELSEs compared to over a thousand IFs. This illustrates how rare an IF ELSE should be.

If an IF ELSE is necessary, the IF should be the short line of code and the ELSE the long line.

REASON

Makes future code enhancements easier.

1.2.3 Loops

RULE

The block of code in FOR NEXT loops must be indented two spaces under the FOR.

REASON

Makes code neater and easier to read. Also makes searches easier.

EXAMPLE

Example 1-29 FOR NEXT Loop Indentation

  for i = 1 to 99999 
    get_line 
    if  eof?  then exit for 
    check_line 
    write_line 
  next i 

RULE

Use parentheses around every set of operations.

REASON

Using parentheses makes it easy to determine the beginning and end of an operation.

This will make it absolutely clear how you intend the code to be executed, without depending on the order of precedence of operators.

EXAMPLE

Example 1-30 Use of Parentheses

! DO:
 
  if  ((a > ( b * c)) or ((d + 4) = f))  then  x = x + 1 // with parentheses 
 
! Instead of:
 
  if  a > b * c or d + 4 = f  then  x = x + 1            // without parentheses 

RULE

Variable names should closely resemble their function.

REASON

Makes it easy to tell the purpose of the variable.

EXAMPLE

Example 1-31 Variable Names

        Line_counter            Line counter 
        
        Page_counter            Page counter 
 
        database_engine_menu    Database engine menu          
 
        student_name            Student name 

RULE

Split a long line logically.

REASON

Shorter lines are easier to follow.

EXAMPLE

Example 1-32 Short Lines of Code

! DO:
 
  open structure payroll: name "c:\sheerpower\my_payroll_master", 
   access outin 
 
! instead of:
 
  open structure payroll: name "c:\sheerpower\my_payroll_master", access + 
    outin 

See Section 5.8, GOLD/F to Fixup Right Margin for instructions on how to automatically wrap long lines of code at the right margin using a specially mapped keystroke in SPDEV.

RULE

Temporary variables and arrays will be single letter variables. They may also be a single letter followed by a number. Note: A temporary variable is one which is used in only one routine. Temporary variables cannot span more than one routine.

REASON

Makes it easy for the programmer to distinguish temporary (and therefore less important) variables in routines.

EXAMPLE

Example 1-33 Temporary Variables as Single Letters

  for (1)i = 1 to 99999 
    get_line 
    if  eof  then exit for 
    check_line 
  next i 

  1. "i" is a temporary variable used only in this routine.

RULE

Underscores are used as separators in all variable names, labels, etc.

REASON

Ensures readability and conformity with other BASICs.

EXAMPLE

Example 1-34 Underscores as Separators

(1)skip_lines: 
    if (2)skip_lines then 
      for z = 1 to 5 
      print (3)#report_ch 
      next z 
    end if 

  1. Notice the underscore used as a separator in this label,
  2. and in this variable,
  3. and again in this variable.


Chapter 2
Routine Naming Convention Standards

Overview

This chapter describes standards for routine naming conventions used in coding.

2.1 Naming Conventions

Names for certain types of routines must follow specific naming conventions. For example, routines whose purpose is to print data to an output file will carry the name PRINT_output filename.

The purpose of providing naming standards is to make the code clearer and to make searches within the code easier. For example, every time the programmer encounters a routine with the name PRINT_filename, it will be clear that the routine's purpose is to print data to an output file. Moreover, if the programmer needs to search for a print routine, a search can be done for the prefix "PRINT_" and the filename, if it is known.

2.2 Standard Naming Prefixes

The prefixes for routine names given in the manual must be used in creating routine names. The prefixes given should cover all program procedures.

These prefixes are standardized according to the rules below, and will help identify the types of routines and make searches easier. The unique text following the prefix will identify the individual routines.

The following conventions will be used in naming routines.

ASK_ Prefix

Routines that ask for a yes or no response will carry the "ASK_" prefix followed by identifying text (for instance, what the routine asks).

Example 2-1 ASK_ Prefix

  Examples:  ask_restoring 
             ask_active 
             ask_guidance_flag 

CALC_ Prefix

Routines that perform calculations will carry the "CALC_" prefix followed by identifying text (for instance, what is being calculated).

Example 2-2 CALC_ Prefix

  Examples:  calc_mm_short_limit 
             calc_customer_line 
             calc_mmloan 

DO_ Prefix

Routines that do processing will carry the "DO_" prefix followed by identifying text (for instance, what processes the routine does).

Example 2-3 DO_ Prefix

  Examples:  do_sale_limit 
             do_fwd_total_limit 
             do_credit_amount 

ENTER_ Prefix

Routines that ask the user to enter text will carry the "ENTER_" prefix followed by identifying text (for instance, what is being entered).

Example 2-4 ENTER_ Prefix

  Examples:  enter_inst 
             enter_instrument 
             enter_cd_amount 

GET_ Prefix

Routines that get a record will carry the "GET_" prefix followed by identifying text (for instance, what record the routine gets).

Example 2-5 GET_ Prefix

  Examples:  get_count 
             get_input 
             get_fxco_record 

OPEN_ Prefix

Routines that open or begin the routine will carry the "OPEN_" prefix followed by identifying text.

Example 2-6 OPEN_ Prefix

  Examples:  open_file 
             open_table 
             open_fxaudi 

PRINT_ Prefix

Routines that print to an output file will carry the "PRINT_" prefix followed by a description of the data.

Example 2-7 PRINT_ Prefix

  Examples:  print_header, 
             print_indiv_info 
             print_images 


Previous Next Contents Index