RPG Academy: /FREE Your Code: Free-Format Pros and Cons

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Welcome to the new sub-series of RPG Academy, the long overdue discussion of free-format RPG.

 

This part of the TechTip series will start by discussing the advantages and disadvantages of this paradigm shift in the way you write your code. Just in case you still need a bit more convincing, let me tell you right now that the advantages drastically outweigh the disadvantages!

 

As the RPG Academy TechTip series progressed, many readers asked why was I still providing examples in fixed-format code. My answer was always the same: "I'll get to free-format, eventually. Let's not change everything at once. Let's provide new stuff in a familiar format so that everybody can follow the discussion." Well, that time has come.

 

If you are one of those readers, think of this TechTip as an early Christmas present.

 

Let me start by telling you that there are a few clouds in this Big Blue sky. As you'll see, some fixed-format operation codes don't have a free-format equivalent, which sometimes makes migrating code to free-format a problem. There are solutions, but there's no magic pill (or tool) that solves all the problems, so you'll need to sink your teeth into those pieces of code, chew them a bit, and spit out free-format code. (Sorry for the strong image.) Also, all this talk you've probably already heard of free-format being "easier to read and write" comes at a price. Indeed, it'll get easier to read and write code in free-format, but the first few attempts at coding in free-format RPG will seem strange, almost alien to you.

 

It takes a bit of getting used to, especially because we have coded in fixed-format for so long. We're simply not used to seeing "everything out of place" with the usual <Factor 1> <Operation Code> <Factor 2> <Result> structure turned upside down. Your eyes and fingers will take a while to get used to it, and it might be a bit frustrating in the beginning.

 

There's one more thing to take into consideration. Free-format requires discipline. If you don't follow guidelines regarding naming, documentation, and indenting (which I'll address in later articles), a piece of free-format code will get as hectic as an old RPG III spaghetti program.

 

But wait! The sky is blue after all. Being free of fixed positions, cryptic names, and several legacy operation codes (more on those in a future article) is perhaps the greatest advantage of free-format RPG, but it's not the only one. You can also (finally) indent your code with very few restrictions, and you can use much longer names everywhere. All of this will improve maintainability and readability, making RPG friendlier for RPGers and non-RPGers alike. Also, as I'll show you in the next article of this series, writing code starting with the operation code instead of factor 1 makes it more logical to write, as well as (adding to the previous point) more readable.

 

There's more. In addition to being easier to read and write, free-format RPG is also more like "modern" languages, making RPG easier to learn by a whole new generation of programmers (and helping you get rid of the whole "programmer from the Jurassic period" aura). Similarly, once you get the hang of it, you'll find that it makes it easier for you to learn other languages, too! This can be helpful in many ways; personally, I found really nice concepts in Java and Python that led to the creation of some extremely useful procedures and functions in RPG.

 

Finally, one big argument for moving to free-format is that IBM won't bring the language's enhancements to fixed-format. (This is something that is already happening, practically since free-format was introduced with V5.) Some of the innovations are simply not implementable with the column limitations, or would be too complicated to implement, thus rendering the code unreadable.

 

If all of this doesn't convince you, I don't know what will!

 

I'll be honest: it might not be easy in the beginning, but you'll get better at it, and soon you'll start to reap the benefits of free-format. Just keep at it, use this and the next few TechTips of this sub-series as your "slow-reference" guide, and don't despair!

 

In the next article, I'll go over the (few) rules you need to follow to for the compiler to correctly validate and compile your code. Until then, feel free to ask questions and add to the pros and cons mentioned in this article, in the comments section below or in the LinkedIn groups where the RPG Academy TechTips usually pop up.

Rafael Victoria-Pereira

Rafael Victória-Pereira has more than 20 years of IBM i experience as a programmer, analyst, and manager. Over that period, he has been an active voice in the IBM i community, encouraging and helping programmers transition to ILE and free-format RPG. Rafael has written more than 100 technical articles about topics ranging from interfaces (the topic for his first book, Flexible Input, Dazzling Output with IBM i) to modern RPG and SQL in his popular RPG Academy and SQL 101 series on mcpressonline.com and in his books Evolve Your RPG Coding and SQL for IBM i: A Database Modernization Guide. Rafael writes in an easy-to-read, practical style that is highly popular with his audience of IBM technology professionals.

Rafael is the Deputy IT Director - Infrastructures and Services at the Luis Simões Group in Portugal. His areas of expertise include programming in the IBM i native languages (RPG, CL, and DB2 SQL) and in "modern" programming languages, such as Java, C#, and Python, as well as project management and consultancy.


MC Press books written by Rafael Victória-Pereira available now on the MC Press Bookstore.

Evolve Your RPG Coding: Move from OPM to ILE...and Beyond Evolve Your RPG Coding: Move from OPM to ILE...and Beyond
Transition to modern RPG programming with this step-by-step guide through ILE and free-format RPG, SQL, and modernization techniques.
List Price $79.95

Now On Sale

Flexible Input, Dazzling Output with IBM i Flexible Input, Dazzling Output with IBM i
Uncover easier, more flexible ways to get data into your system, plus some methods for exporting and presenting the vital business data it contains.
List Price $79.95

Now On Sale

SQL for IBM i: A Database Modernization Guide SQL for IBM i: A Database Modernization Guide
Learn how to use SQL’s capabilities to modernize and enhance your IBM i database.
List Price $79.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: