ARexx - Coding conventions

I try to maintain a consistent set of conventions with my ARexx 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 */

ARexx 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 ARexx'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. ARexx 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 like this...


   CSI         = '9b'x               /* Control Sequence Introducer */

   ESCAPE      = '1b'x

   RESET       = ESCAPE||'63'x       /* clears the Shell window */

   INVERSE_ON  = CSI||'37'x||'6d'x   /* inverse-video style command */    

   INVERSE_OFF = CSI||'30'x||'6d'x   /* plain-text style command */  

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 and in the above example definitions for instance it means that instead of writing magic number expressions such as...

   say '1b'x||'63'x

   say '9b'x||'37'x||'6d'x  'cannot find file' '9b'x||'30'x||'6d'x  

this, more readable, equivalent can be used...

   say RESET

   say INVERSE_ON 'cannot find file' INVERSE_OFF 

I frequently go further than this and use the technique for eliminating embedded text messages as well. For example, the definition...

   NO_FILE  = 'cannot find  file'

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

   say INVERSE_ON NO_FILE INVERSE_OFF 

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 an ARexx 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.INVERSE_ON  = g.CSI||'37'x||'6d'x   /* inverse video */ 

   g.INVERSE_OFF = g.CSI||'32'x||'37'x||'6d'x /* inverse off */ 

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 ARexx scripts.


Go back toReturn to page at previous level

Go back toReturn to main index page

Page last updated 21-Nov-96