× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On 5/15/2017 5:43 PM, Booth Martin wrote:
Also, it looks to me like the same underlying code gets written,
whichever solution is chosen. All that differs is how the code is
bundled and delivered.

Almost.

I'm going to use RPG for this example because that's the language I use.
Cobol would have a similar design.

Imagine I have a business need to calculate the weight of an I-beam
based on the material and dimensions. If I were to write it as a
program, the interface would be the parameters:

call iweight
parm material
parm len
parm width
parm height
parm webthick
parm flangeth
parm weight

You can pretty it up some by wrapping that in a PR, but the key concept
here is that the answer comes back in a parameter. A variable that
needs to be declared, initialised, stored, referenced, etc.

If I wrote it as a sub-procedure, I can return the value on the RETURN
statement:

weight = ibeamWeight(material: length: width: height: webThickness:
flangeThickness);

More interestingly, I don't need to store the result at all:

if ibeamWeight(material: length: width: height: webThickness:
flangeThickness) > smallTrailerWeightLimit;
useLargeTrailer = *on;
else;
useLargeTrailer = *off;
endif;

Both implementations return a value, but the sub-procedure form has a
more... natural feel to me.

Again, to be clear, there's no absolute wrong answer. On S/38 I wrote
lots of small programs that acted like functions - do one and only one
thing. Making an architecture like this performant takes some effort,
but it's totally do-able.

I use sub-procedures today, not only to replace subroutines, or to reuse
code, but to help me crystallise my thinking along the lines of 'what
functions do I need?' It turns out that the default setup for
sub-procedures is performant right out of the box, so that's a bonus.

The final thing I'd like to mention is Mihael Schmidt's RPGUnit. Thomas
Raddatz has forked the project and made it part of RDi via the iSphere
plug-in. I'm only going to say that I don't write a sub-procedure
without a test and I very much like it that way. I have extreme
confidence that my changes don't inadvertently break something when the
tests come back green. Works with sub-procedures, not program calls.
TDD (Test Driven Development) rocks my world.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.