REXX - Coding conventions

I try to maintain a consistent set of conventions with my REXX code. With real variables, ie variables whose values do change, I use lowercase names with the underscore character to improve readability. For instance...

    exit_flag = FALSE    /* clear exit flag - user  */
                             /* has decided not to quit */

REXX variables are typeless but I'm an "old school" coder who believes that it is useful for a variable name to imply something about the type of data being held. Consequently you will notice, particularly in my larger scripts, $ suffixes being added to variables which are used to hold text strings. In practice this means that I would tend to use variables such as value$, x$ etc., to collect general input strings from a user. If on the other hand if it were known that user input was going to be USED AS A NUMBER then obviously variable names without a $ suffix (value, x and so on) would be used. I should point out that this is not a common ARexx convention and, because of this, have of late deliberately tried to minimise it's use. You will however find $ variables used in much of my older code.

With some advanced applications additional C-style conventions (such as prefixing global variables with the character g_ and suffixing pointer variables using _p) are adopted. This again allows the contents of a variable to be implied from its name!

Function Names

With function names I capitalise the first letter of each part of the function name. CalculateVolume(), GetReply(), CollectResponse() etc. This is essentially done to aid readability and the same convention is adopted with REXX's built in functions as well.

Symbolic Constants

I try never to use absolute constants within the bulk of my scripts and instead define such items as part of a special initialisation block. REXX does not provide much help here but named constant values can however be set up simply by loading values into variables (which are subsequently never changed). My preference is to adopt the C-style convention of using uppercase names for values which are constant and, by placing such definitions near the start of a script I always know where to look for them when making changes.

And of course, because symbolic names, rather than the underlying definitions themselves, are used scripts are infinitely more readable. This 'trick', incidentally, is especially useful when dealing with control character sequences. The same technique can also be used to eliminate embedded text messages as well. For example, the definition...

   NO_FILE  = 'cannot find  this file'

allows the above error message to be displayed using...

   say NO_FILE

The important point about this approach of course is that the message is defined in a single place. So, changing the initial definition would automatically ensure that the updated message was subsequently used in all parts of the program that contained a NO_FILE reference!

Use of Globals Within Procedures

When a REXX function is defined as a procedure any pseudo-constants (which are of course in reality global variables) needed by the function will only become visible if they are exposed. My favourite way of doing this is to prefix such items with 'g.', ie turn them into a compound variable set whose stem is g. like this...


   g.root='C:\PAO-WORK\SiteCreator\'

   g.srcdir=g.root||'SourceText\'

   g.textdir=g.root||'PageText\'

   site_plan=g.root||'site_plan'

which allows me to expose a whole set of definitions by just exposing the g. stem! This convention, incidentally, tends to be used mainly with larger REXX scripts.


Go back toReturn to page at previous level

Go back toReturn to main index page

Page last updated 21-Nov-96