Sheerpower®
A Guide to the Sheerpower Language


Previous Contents Index

3.7.1 (//) Comment Text

FORMAT:


        // comment text 

EXAMPLE:

Example 3-21 Comments in Programs

  input 'Please enter your name': name$   // ask for a name
  print 'Hello, '; name$                  // say hello
  end
 
 
Please enter your name? Mike 
Hello, Mike 

PURPOSE:

All programs should be well documented with comments. Comments teach future programmers, as well as yourself, how a program works. The proper use of comments can dramatically enhance the ability to maintain a program.

Comments are used to put headers in routines, and to comment code within routines. Always document code thoroughly in each routine header. Ideally, commenting should rarely be done inside the actual routine. If the routine is written simply and kept short, then no comments are needed within the code. Keep the size and scope of the routine limited and obvious for future reference.

DESCRIPTION:

Comments are used to clarify parts of your program as shown in the example above.

When the program source code is listed or printed, the commented line is displayed as it was written.

When Sheerpower executes the above program, it executes the INPUT statement, ignores the "//" and the comment text following it, and continues execution at the PRINT statement. The "//" does not have to be placed at the beginning of a physical line. It can be indented on its own line, or placed at the end of a line of code as well. For example:


// this comment will work 
     // this comment will also work 
  input 'Tell me your name'; name$ 
  print 'Hi there '; name$ // this comment works too 
  end 
  
 
Tell me your name? Suzanne 
Hi there Suzanne 

3.7.2 Routine Headers

In SPDEV, the GOLD/r keystroke automatically creates the routine header template. The 'GOLD' keys in SPDEV are the [Esc] (Escape) key or the [NumLock] (Numbers Lock) key. For more special keystrokes in SPDEV, refer to Appendix F, Keystrokes for Sheerpower Rapid Development Environment.

Below is an example of a Routine Header used to document each routine:

Example 3-22 Routine Header Sample

!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
! f i n d _ p e a k _ c a m s _ a n d _ v i e w e r s 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
! 
! Brief description: 
!   This routine finds the peak number of cams logged in and peak 
!   number of live viewers watching each day. 
! 
! Expected on entry: 
!   total_live_viewers = number of live viewers 
!   live_cameras       = number of live cams 
! 
! Locals used: 
!   none 
! 
! 
! Results on exit: 
!   peak_viewers       = peak number of live viewers 
!   peak_cameras       = peak number of live cameras 
! 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

3.7.3 Comments With Line Continuation

The double-forward slash "//" can be used after an ampersand to document continued lines in a program. When a line of code is continued with an ampersand, any comments must follow the ampersand. For example:

Example 3-23 Comments With Line Continuation

  input a$ 
  if  a$ = ''  then  print a$; &     // here is the trailing
      ' is OK.'                      // comment text
  end

3.8 Debug Comments in SPDEV

Code that is inserted into a program for the sole purpose of debugging the program should be marked with a debug comment. Sheerpower can automatically create a debug comment line for you with a special keystroke.

The GOLD/C keystroke is mapped to create a debug comment line. In SPDEV, a GOLD key is a special key that allows you to utilize other keys for different purposes. The GOLD key is either the [Esc] (Escape) key or the [NumLock] (Numbers Lock) key. See Appendix F, Keystrokes for Sheerpower Rapid Development Environment for more special Sheerpower Rapid Development Environment keystrokes.

To perform the GOLD/C keystroke, place the cursor where you want the debug comment line created. Press once on the [Esc] key or the [NumLock] key. Let go and look in the bottom right hand corner of the SPDEV window. Sheerpower tells you if your GOLD key is activated by highlighting a small square in the bottom frame in black, with gold letters that say 'Gol'. Now you can press the [C] key, and a small dialog box will appear asking you for your initials. Leaving your initials will allow future programmers (as well as yourself) to know who inserted this line of debug code. Enter your initials, and click on 'OK'.

Example 3-24 Debug Comments

!++ debug SMW July 20, 2015 

The '!++' at the beginning of every line of debug comment makes it very easy to perform a search and find all lines containing debug code.

3.9 Program and Compile Directives

The following sections describe the directives that are available for use in your programs. These directives are invoked when the compiler builds a program and/or when a program is compiled.

3.9.1 %COMPILE

FORMAT:


        %COMPILE 'quoted_text' 

EXAMPLE:

Example 3-25 %COMPILE Program Directive

  print 'This is a test program.' 
  %compile 'Text that you want to be seen inside the SPRUN file...' 
  %compile 'Up to 100 lines of text can be seen here!' 
  end

DESCRIPTION:

Using the DEPLOY feature you can make portable runnable applications (.SPRUN files). These files are plain text, and can be password protected.

SPRUN files allow you to distribute Sheerpower programs without your source code being seen.

An SPRUN file can be easily copy/pasted, emailed or embedded into a website. This allows for simple distribution of an application.

The %compile text is truncated at 72 characters. There can be up to 100 %compile text lines in a program.

Once the text is inside the SPRUN file, if it is altered in any way the SPRUN file will not run! This is a good place to put copyright notices and license agreements, etc.

3.9.2 %MESSAGE

FORMAT:


        %MESSAGE 'quoted_text' 

EXAMPLE:

Example 3-26 %MESSAGE Program Directive

  %message 'Including HELP module' 
  %include 'sptools:help' 
  end

DESCRIPTION:

This compiler directive displays a message, quoted_text, on the message line. The message is displayed when a program is built into a workspace or compiled.

3.9.3 %MESSAGE ERROR

FORMAT:


        %MESSAGE ERROR: 'quoted_text' 

EXAMPLE:

Example 3-27 %MESSAGE ERROR Program Directive

  %message error: 'Using experimental HELP module' 
  %include 'sptools:help' 
  end

DESCRIPTION:

This compiler directive makes an alert sound and displays the message when a program is compiled.

3.9.4 %INCLUDE

FORMAT:


        %INCLUDE 'file_spec' 

EXAMPLE:

Example 3-28 %INCLUDE Program Directive

   %include 'sptools:example' 

PURPOSE:

%INCLUDE allows you to put common subroutines into a separate file to be shared among applications.

DESCRIPTION:

%INCLUDE includes a source code file into the current Sheerpower program. The default extension for a Sheerpower included file is .SPINC.

3.9.5 %INCLUDE CONDITIONAL

FORMAT:


        %include conditional: 'file_spec' 

DESCRIPTION:

If the file to be included does not exist, no error is generated. This allows programs to conditionally include modules.

%INCLUDE CONDITIONAL includes a source code file into the current Sheerpower program if the file to be included is found. The default extension for the included file is .SPINC.

3.9.6 %DEBUG

FORMAT:


        %DEBUG Sheerpower_statement 

EXAMPLE:

Example 3-29 %DEBUG Program Directive

  %debug print 'DEBUG Items' 
  end
  
  
DEBUG Items 

DESCRIPTION:

The %DEBUG directive gives an error only if an image compile (/COMPILE) is being done. A %debug statement will return a fatal error when you attempt to VALIDATE or DEPLOY the program. Use this directive to make sure that DEBUG code does not show up in production applications.


Previous Next Contents Index