Midrange Computing recently featured an a short discussion that started as a question about whether it was better to write RPG-ILE as free format, or is it better to use the “RPG cycle”? A newbie’s kind of question because these are two different discussions.
“It’s not about performance. Only one application in 300 needs to worry about performance. It’s about readability. It’s about me being able to go into your code and figure out what you did and how to change it – and that is where Free has it all over traditional code (especially if you are using the RPG cycle which should never be used). “
I have to agree with Dave.
I have seen traditional code that was “structured” in such a way that it was easily read, even with all of the indicator usage of RPG using fixed position coding.
I have also seen some very terribly hard to read code that was written in /free.
The bottom line is: code must be written, regardless of the language or formatting, so that it is easily readable. if you have a programmer who has not been able to make the move to /free (RPGIV), but writes good formatted code that has a solid foundation, requires little maintenance and is easily readable, you are better off (in my opinion) than someone who writes in /free, but has no idea how to write structured code.”
the bottom line is: code must be written, regardless of the language or formatting, so that it is easily readable. if you have a programmer who has not been able to make the move to /free (RPGIV), but writes good formatted code that has a solid foundation, requires little maintenance and is easily readable, you are better off (in my opinion) than someone who writes in /free, but has no idea how to write structured code.”
The fact is that the right answer has changed with time, with the colossal game-changing enhancements to RPG, and with the advancements in hardware.
A long, VERY long time ago, when RPG-II ruled, somebody from IBM apparently told code writers that subroutines slowed things down, that keeping everything in-line improved performance. Maybe the person that said this conditioned it, but if it was true it would be because the compiled code had to swap in and out of RAM from disk. When hardware was a real constraint on performance, then if your subroutine was only called once, maybe even twice, then yeah, you can drive it faster in-lining the code instead of using a subroutine.
But in one talk by John Sears, a great figure in RPG in the IBM midrange world, now retired, he answered the question by saying “If you have a problem with performance, subroutines are not your problem, you should look elsewhere”.
THE RPG CYCLE: USE THE CYCLE OR NOT?
Ask me today, I’ll tell you forget the cycle. At one time when I taught AS/400 programming (Note to Trevor: it was an AS/400 then), I taught the class about the RPG cycle, because out in the shops in business, they were going to find it all over the place in most of the programs they encountered and they would have to understand it if they were going to do code maintenance.
At one shop in my past, one developer told about a program that was using the cycle to read the one primary header file (for SQL guys, that would be the first appearance in your FROM clause), but then use a SETLL and READE to read through the detail records, say, for an invoice.
At that time, that equipment, it took a day and a half sometimes to run. Too long.
So he ripped up some of the code and converted the detail file into a secondary file in the specs, and used matching-record fields and indicators to synchronize the file inputs, and instead of taking one or two days the report finished in a couple of hours. (At this any veteran RPG programmers are groaning, glad all that’s over).
Now you can still program in the most recent version of RPG, but to get similar performance you can now use embedded SQL. Don’t look back. Even if you have to use the other method, (reset file pointers for the detail file for each input of the header file), I think we are all better off leaving the primary and secondary files out of the code. (For newbies, primary and secondary files are specs that “take advantage” of the compiler’s cycle).
Some of the COBOL programmers learning RPG were perplexed: “But where do you open the file? When do you read it”?
In fact it was fun to watch the evolution in code I came across about that time and afterward, and how a lot of programmers were abandoning the cycle but to write a report program they were jumping through all kinds of hoops and loops and conditions and temporary hold fields and the like. I found a way to simulate it, sort of, inside an RPG loop, even when using an SQL cursor to do it.
Now that I’m working these days with a lot of COBOL code, it’s interesting to see how the reports are handled. Stuff that was easy, fast coding in RPG using the cycle.
The cycle is one thing left over from the very beginnings and still supported in the most recent releases of the IBM compiler for RPG, now RPG-IV, RPG4, or RPG-ILE. Give IBM credit: For every release of the operating system and the of the RPG compiler, they have not broken the older stuff, like Microsoft always does.
With some of the more well-known names in IBM midrange development, I agree that some things they could have and should have broken. But in this IBM has respected business continuity considerations and don’t-break-it methods that business has not known enough to appreciate, in my opinion.
So here’s my bottom line for anybody still using it: DITCH THE CYCLE.
It won’t be too long before this admonition will look “quaint”, as in “antiquated”, but the question was posed rather recently. The compiler team has even provided a way to run a program without the cycle, and without having to use the ubiquitous *INLR indicator.
Next, or at some future time, I’ll write about some of my design and coding philosophies.
- Is RPG a “Dead Language”? – My reaction to Mel Beckman’s article at iPro and the reactions (infosmarts.wordpress.com)
- Static versus Dynamic Linking (bytecrunchers.wordpress.com)
- New IBM i exercises in the Power Systems sandbox (ibm.com)
- Six lessons I learned about writing software (betanews.com)
- Perl hijinks (purinchu.net)
- Find Duplicated COBOL Code with CloneDR™ for Rational Developer for System z (prweb.com)
- Lessons from @torvalds/GitHub commits discussion (karmanebula.com)
- Announcing our Open Source Bridge 2012 lineup! (opensourcebridge.org)
- Web Data is Big Data (zdnet.com)
- Has programming lost its way? Part Two (betanews.com)
- QArt codes (halfblog.net)
- In defense of the open web (scripting.com)
- ACBF, an open/free digital comics format (craphound.com)
- The Open Brand, a framework for defining brands (dcurt.is)
- Email is evil (yosefk.com)
- Jim Kielman: Ubuntu Forums Ubuntu +1 update for March 17/2012 (cariboo907.blog.com)
- Open Data and The New Divide (blogs.gartner.com)
- Ask Slashdot: Open Source Tax Software? (ask.slashdot.org)