Progress Programming Tips

By Rod Gaither (rdg@worldinfo.com)


PPT-21  Dealing with return values

Tip:

You often need the caller of a procedure to be able to check some
status or return code indicating the procedure's result.  Below are
three techniques with some pros and cons.

1.  Use RETURN "Something" and the RETURN-VALUE function.

Pros -

  Doesn't add extraneous parameters to procedure calls.
  Works for both internal and external procedures without
  modification. Requires no extra variable setup or maintenance. Can
  be used in a variety of situations, including packed data values.

Cons -

  Limited to a single string value.
  Is impacted by sequence of call/check statements.

2.  Use an OUTPUT PARAMETER.

Pros -

  Directly ties the return value to the procedure call.
  Can use a variety of different data types.

Cons -

  Requires a variable to return into.
  Adds a parameter to the procedure call.

3.  Use an externally defined variable or data structure.

Pros -

  Allows for more complex return values.
  Makes status information visible to more than one place.

Cons -

  Requires global or shared data with external procedures.
  Is very subject to unwanted tampering, value changing.


Each of these methods has its place but a word of caution for 1
and 3.  For number 1 be very careful about checking the
return-value immediately, without any chance of another run
happening (Beware include based runs...).  If you don't then the
con of being impacted by sequence will make for very difficult to
trace bugs.  For number 3 the same side effect problem exists and is
best used when a general status is being set, rather than a simple
success/failure return flag.

Another location to consider putting status and return
information is the PRIVATE-DATA attribute available on widgets,
system handles, and persistent procedures.  This attribute can
be used as a persistent, carry it where you go kind of storage.

Wisdom:

Standardize, Standardize, Standardize!  Put tools, documents, and
procedures in place to help manage the definition, retrieval, and
usage of standards.


Rod Gaither                  | rdg@worldinfo.com
World Information Systems    | (910) 333-2580  Voice
Greensboro, NC               | (910) 333-2584  Fax