MainframeSupports
tip week 18/2004:

One of my colleauges, Peter Hagedorn, once showed me a REXX trick that he had seen somewhere else. The idea is to use the comments in a REXX program as help text for the program itself. I think it is a fantastic idea, especially because it is very simple to implement in REXX. The same idea is almost impossible to use in any other programming language I know of.

As usual the best way of showing how this kind of idea works is by using an example:

/* REXX */
/* This REXX illustrates */
/* how comments in a REXX program */
/* can be used as help text */
COMMENTLINE = 1
DO WHILE SUBSTR(SOURCELINE(COMMENTLINE), 1, 2) = '/*'
  SAY LEFT(SOURCELINE(COMMENTLINE), 72)
  COMMENTLINE = COMMENTLINE + 1
END
EXIT

SOURCELINE is a REXX function that returns the contens of a specific line of source code. The sourceline number is given to SOURCELINE as a parameter. You can use it together with INTERPRET, if you really want to make totally unreadable and incomprehencible programs. When you use it like in the example above SOURCELINE is totally harmless and very useful. Now it is up to you to benefit from this idea in a way that you find suitable. The possibilities are countless and suddenly it becomes much more productive to make comments.

The REXX interpreter makes a kind of "just in time" compilation before execution. The compilation normally compresses the source code which includes removal of all comments before execution. The compression is for obvious reasons not done when you use the SOURCELINE function in your program. Therefore SOURCELINE can slow down the execution speed of your REXX programs.

Previous tip in english        Sidste danske tip        Tip list