Touch Technologies, Inc.
Coding Standards


Previous Contents Index

5.1 GOLD/P Program Template

A PROGRAM TEMPLATE can also be created instantly inside a program file by using the GOLD/P keystroke inside SheerPower Rapid Development Environment (SPDEV).

You can change the name and/or company name displayed in the Program Header at any time by clicking on Options in the SPDEV toolbar, then selecting Change System Settings.

Example 5-1 GOLD/P to Create Program Template

!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
! Program: Sample Program Template 
! System : 
! Author : my name 
! Company: my company name 
! Date   : October 11, 2003 
! Purpose: 
! 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
 
 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
!         I n i t i a l i z a t i o n 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
 
 
 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
!         M a i n   L o g i c   A r e a 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
 
 
 
stop 
 
 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
!         R o u t i n e s 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
 
 
 
end 

5.2 GOLD/R Routine Header Template Keystroke

In SPDEV, you can bring up a standard routine header template using the specially mapped keystroke GOLD/R. Simply position the cursor at the place in your program where you want to insert a new routine, then press GOLD/R. A routine header dialog box will appear, prompting you to type in the name of your routine and any parameters to include. Once the fields have been completed, click on the OK button. The routine template will appear in your program file. A sample routine template is shown below:

Example 5-2 GOLD/R to Create Routine Template

!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
! s a m p l e _ r o u t i n e _ t e m p l a t e 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
! 
! Brief description: 
!    
! 
! Expected on entry: 
!    
! 
! Locals used: 
!    
! 
! Results on exit: 
!    
! 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
routine sample_routine_template 
 
end routine 

5.3 GOLD/R to Create Subroutines

Often routines can become too long and complicated. SheerPower makes it easy to make SUBROUTINES from within a routine. Just highlight the block of code you want moved into a new subroutine, and press GOLD/R.

The new routine will automatically be created with the highlighted code inside of it. A "call" to the new routine will be inserted inside the original routine where the highlighted code used to be. This makes breaking up long routines much simpler for any programmer.

Example 5-3 GOLD/R to Create Subroutine

  n = 301.84 - 301 
  if (n = .84) then 
    print 'Perfect Precision' 
  else 
    print 'Not quite right' 
  end if 
 
! Highlight this section of code below 
! with your mouse, then press GOLD/R:
 
  x = 0                
  for i = 0 to 1000    
    x = x + 0.01 
  next i 
  z = 10.082 - 0.072 
  if (x = z) then 
    print 'Perfect Precision' 
  else 
    print 'Not quite right' 
  end if 

After you press the GOLD/R keystroke, you will be prompted for the name of the new routine and any parameters you wish to include. The highlighted code will then be placed into its own routine, and in its original place the call to the new routine will be inserted as shown below:


  n = 301.84 - 301 
  if (n = .84) then 
    print 'Perfect Precision' 
  else 
    print 'Not quite right' 
  end if 
 
  sample_subroutine  ! <--CALL to new subroutine
 
 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
! s a m p l e _ s u b r o u t i n e 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
! 
! Brief description: 
!    
! 
! Expected on entry: 
!    
! 
! Locals used: 
!    
! 
! Results on exit: 
!    
! 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
routine sample_subroutine 
  x = 0 
  for i = 0 to 1000 
    x = x + 0.01 
  next i 
  z = 10.082 - 0.072 
  if (x = z) then 
    print 'Perfect Precision' 
  else 
    print 'Not quite right' 
  end if 
end routine 

5.4 GOLD/O to Organize Routines

Routines can become logically out of order as a program is being written or modified, making it difficult to follow program logic and to find a given routine.

In SPDEV, the GOLD/O keystroke lets you automatically order your routines in either CALLING ORDER or ALPHABETICAL ORDER. The default order in SPDEV is calling order.

To use the GOLD/O keystroke, from anywhere in the program file press either GOLD key (Escape or Num-Lock), let go, then press the O key. A dialog box will appear prompting you to choose the calling order of the routines, as shown below:

Once the calling order is selected, press the OK button to proceed with the routine organization.

5.5 GOLD/A to Align Equal Signs "="

To keep routine headers and code neat in appearance and easy to read, alignment of equal signs (=) is important. In SPDEV you can align the equal signs quickly by highlighting the block of code or text containing the equal signs to be aligned, then pressing GOLD/A. This is illustrated in the following example:

Example 5-4 GOLD/A to Align Equal Signs " ="

! To align the = in the example below, highlight all of the 
! text containing the = to align with your mouse:
 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
! g e t _ h e a d l i n e 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
! 
! Brief description: 
!   Go out to www.cnn.com and extract the headline of the top 
!   news story. 
! 
! Expected on entry: 
!   main$ = the starting point of the headline 
!   begin_form$ = the top HTML code for the dialogbox form 
!   end_main$= the end point of the headline 
! 
! Locals used: 
!   text$ = the HTML code on the CNN website 
!   crlf$= contains the character line feeds 
!   state$= tells which action needs to be 
!            performed next on the incoming data 
! 
! Results on exit: 
!   dbox$ = stores the code to create the dialogbox 
! 
!   The headline is found and the form is created. 
! 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

Now press GOLD/A. SheerPower automatically aligns the = to make the routine header appear neater and easer to read. For example:


!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
! g e t _ h e a d l i n e 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
! 
! Brief description: 
!   Go out to www.cnn.com and extract the headline of the top 
!   news story. 
! 
! Expected on entry: 
!   main$       = the starting point of the headline 
!   begin_form$ = the top HTML code for the dialogbox form 
!   end_main$   = the end point of the headline 
! 
! Locals used: 
!   text$  = the HTML code on the CNN website 
!   crlf$  = contains the character line feeds 
!   state$ = tells which action needs to be 
!            performed next on the incoming data 
! 
! Results on exit: 
!   dbox$  = stores the code to create the dialogbox 
! 
!   The headline is found and the form is created. 
! 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

The same can be done to align = within a block of code as shown below:

Example 5-5 Aligning " =" in Code

! Copy/paste the 3 lines of code below into SPDEV, then
! highlight with your mouse:
 
text$= "Hello there!" 
a$= "It's another sunny day in paradise here!" 
value  = 10 
 
! Press GOLD/A to have all the = aligned as follows:
 
text$ = "Hello there!" 
a$    = "It's another sunny day in paradise here!" 
value = 10 

5.6 GOLD/C to Insert Debug Comment Line

The GOLD/C keystroke inserts a unique debug comment line beside any debug code to make it easy to find later and remove. When this keystroke is first used, a dialog box will appear prompting you for your initials:

Once the initials are entered, click the OK button. The debug comment will then be inserted where your cursor is inside the program file.

Example 5-6 GOLD/C to Generate Debug Comment

!++ debug sw October 11, 2003 

The initials placed inside the debug comment line can be changed at any time by clicking on Options in the SPDEV toolbar, then choosing Change System Settings. In the top right corner of the Settings dialog box the Initials field can be edited.

5.7 GOLD/D to Document Routine Variables

Documenting variables in routines clearly in a routine header is essential to creating professional code. SheerPower makes this simpler with the GOLD/D keystroke. You can create the routine header using the GOLD/R keystroke, write the routine, then document all the variables using GOLD/D. See the following example for how GOLD/D works:

Example 5-7 GOLD/D to Document Routine Variables

! The following routine has been written, but the header has yet to
! have all the routine's variables listed and documented within it:
 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
! 
! Brief description: 
!   
! 
! Expected on entry: 
! 
! 
! Locals used: 
! 
! 
! Results on exit: 
! 
! 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
routine print_output 
  open  #1: name 'test.txt', access output 
  print #1, using '{ucase}?': 'first line' 
  print #1: tab(5); 'second line' 
  close #1 
  open  #1: name 'test.txt' 
  line input #1: record_1$, record_2$ 
  print record_1$ 
  print record_2$ 
  close #1 
  end 
end routine 

To document the routine variables, place your cursor anywhere in the routine and press GOLD/D. The Document Routine Variables dialog box will appear:

Fill in the variable description for each variable by selecting the variable in the list, then type in the description. Choose whether the variable is Expected, Local, a Result, or if it should be Ignored and not documented. Click on the OK button when you are done. The variable names will be inserted into the routine header under the appropriate heading with the description as shown below:

Example 5-8 Documented Variables with GOLD/D

!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
! 
! Brief description: 
!   
! 
! Expected on entry: 
! 
! 
! Locals used: 
! 
! 
! Results on exit: 
!> record_1$ = first line of data printed in the text file 
!> record_2$ = second line of data printed in the text file 
! 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
routine print_output 
  open  #1: name 'test.txt', access output 
  print #1, using '{ucase}?': 'first line' 
  print #1: tab(5); 'second line' 
  close #1 
  open  #1: name 'test.txt' 
  line input #1: record_1$, record_2$ 
  print record_1$ 
  print record_2$ 
  close #1 
  end 
end routine 

At this point all the programmer needs to do is ensure that the rest of the routine header is completed and accurate for future programmers to understand.


Previous Next Contents Index