• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Guru: Eliminate The Legitimate Use Of GOTO, Take Two

    February 27, 2017 Ted Holt

    I was annoyed that IBM chose not to support GOTO and TAG in free-form RPG calculations. I rarely used those opcodes, but when I did, it was in disciplined situations when nothing else would do. Besides, I didn’t want to be treated like a baby. Now it’s a non-issue. IBM finally provided an alternative to the last legitimate use of GOTO.

    Almost five years ago, I wrote about a situation that I come across from time to time, namely the need to execute a clean-up routine before exiting an RPG subprocedure. Since nothing forbids a subprocedure to have multiple exit points, it is common to see more than one RETURN operation within a subprocedure. The problem is that RETURN immediately leaves the subprocedure without executing the clean-up code. In those cases, I replace RETURN with a GOTO that branches to the clean-up routine.

    Until now. IBM recently added a feature that allows us to specify code that needs to run upon exit from a subprocedure. GOTO is gone from my RPG code!

    Look at this comparison of part of the code with GOTO (on the left) and the new code without GOTO (on the right).

     

    To me that’s serious progress, but maybe I get too excited over little things.

    It’s been almost 50 years since Edsger Dijkstra alerted the computing world to the intrinsic harm in GOTO. Yet even today, programmers whose motto seems to be, “When in doubt, GOTO,” are paid to sling code.

    Why do I hate GOTO so much? It’s a case of sour grapes. I’m not smart enough to understand programs that use it.

    RELATED STORIES

    Eliminate The Legitimate Use Of GOTO

    New for RPG in IBM i 7.2 and 7.3 – ON-EXIT section to be run whenever a procedure ends

    Edsger Dijkstra: Go To Statement Considered Harmful

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags: Tags: GOTO, Guru, IBM i

    Sponsored by
    Chilli IT

    Chilli is one of the UKs leading IBM support and management providers with 20 years’ experience in the power and storage industry. Our bespoke solutions for maintenance, security and infrastructure delivers a service which is cost effective, increases productivity and enhances efficiency. Our ethical approach and unrivalled knowledge has secured business partnerships with blue-chip companies in the technology, retail, banking and travel sectors.

    As an IBM Business Partner, we provide you with the peace of mind that you are working in partnership with a company accredited to the highest standard. Our team of experts have worked together for many years and deliver projects which include consolidation, High Availability, Operating System upgrades; and backup and recovery installations.

    Contact us to see how we can help your business with IBM support and management.

    www.chilli-it.co.uk

    info@chilli–it.co.uk

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    As I See It: Expanding Reach And Shrinking Intelligence IBM i Community To Get Closer Look At Watson

    6 thoughts on “Guru: Eliminate The Legitimate Use Of GOTO, Take Two”

    • Justin Taylor says:
      February 27, 2017 at 9:02 am

      I always just coded an exit subroutine, and executed it in place of all the returns.

      Reply
      • Ted Holt says:
        March 4, 2017 at 11:42 pm

        That is a clever technique, Justin, and it never occurred to me. Thanks for sharing it with the rest of us.

        Reply
    • Dan Lovell says:
      February 27, 2017 at 11:53 am

      There is NEVER a reason to use GOTO or TAG in 2017. NEVER. Several languages don’t even have GOTO such as Java, C#, many others…

      Reply
    • Reeve Fritchman says:
      February 27, 2017 at 12:11 pm

      Ted, the GOTO flap was actually tongue-in-cheek. The topic took on a life of its own and became a rally cry for those whose proudest accomplishment was to deliver a huge monolithic program without a single GOTO. Of course, trying to understand that logic was a bear.

      I’m with you WRT IBM’s petulance on free-forming GOTO and TAG–IBM’s failure to address these unsophisticated op codes has likely slowed adoption of free-form RPG. Many users told me they didn’t think IBM was serious about free-form because this.

      I had many interactive programs using GOTO to control program navigation (I supported a help screen and many command key functions) and finally wrote a program to strip out the GOTO’s. IMO, the resulting programs are harder to follow unless your source is carefully and consistently indented, which means you’re using RDi (and if not, why?). If you use GOTO for calculation loops, you’re not a programmer or even a good coder–you’re a very bad coder.

      I believe a “prosper program” has a single entry point and a single exit point. So, peppering your code with RETURN’s may be convenient but it’s not a best practice. Finally, IBM has addressed the issue!

      My solution has been to put my exit code in a subroutine within the procedure. It appears to work fine.

      -reeve

      Reply
    • Ken Holway says:
      March 3, 2017 at 2:56 am

      Goto occasionally has a use when you have very very old code that has been hacked to pieces. Often converted from OPM
      Remember, most of developers time is hacking old code, not writing shiny new programs.

      Reply
    • trutherator says:
      March 5, 2017 at 11:22 am

      It’s annoying when you’re converting old code, but the net effect in my opinion is positive.

      Your justification for using GOTO when you do is perfectly correct. It is good.

      The issue for your code specifically is when others have occasion to eyeball your code.

      But there is a bigger scope involved for compiler makers. The removal of GOTO from the clutches of lazy programmers (meaning not you) that abuse this rarely useful operation code forces relieves you and me from dealing with spaghetti that is too tangled up to parse within a reasonable time, like say, a year.

      🙂

      Reply

    Leave a Reply Cancel reply

TFH Volume: 27 Issue: 12

This Issue Sponsored By

  • Fresche
  • Profound Logic Software
  • WorksRight Software
  • Computer Keyes
  • Northeast User Groups Conference

Table of Contents

  • Security Awareness: Eight More Patches For IBM i Vulns
  • IBM i Community To Get Closer Look At Watson
  • Guru: Eliminate The Legitimate Use Of GOTO, Take Two
  • As I See It: Expanding Reach And Shrinking Intelligence
  • What’s Wrong With Modern RPG?

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Guild Mortgage Takes The 20-Year Option For Modernization
  • IBM i Licensing, Part 3: Can The Hardware Bundle Be Cheaper Than A Smartphone?
  • Guru: The Finer Points of Exit Points
  • Big Blue Tweaks IBM i Pricing Ahead Of Subscription Model
  • We Still Want IBM i On The Impending Power E1050
  • DRV Brings More Automation to IBM i Message Monitoring
  • Managed Cloud Saves Money By Cutting System And People Overprovisioning
  • Multiple Security Vulnerabilities Patched on IBM i
  • Four Hundred Monitor, June 22
  • IBM i PTF Guide, Volume 24, Number 25

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2022 IT Jungle

loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.