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

  • 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.