.st0{fill:#FFFFFF;}

RPG Program Source Code – Clever or Clear? 

 August 8, 2017

By  NickLitten

I’ve been working on an interesting project focused on taking some old RPG code and re-factoring it to make it more efficient. Fascinating work for a client that is focused on doubling its IBM i throughput and reducing the CPU load of all its old programs. This has frequently made me choose between writing a single line of %BIF’d up code that looks slick and minimalist – or – using clear rpg programming standards aka: writing multiple lines of code that are more readable and arguably (marginally) less efficient.

/me remembers the AS400 “SETON vs MOVEL *ON” arguments of yesteryear with a fond smile…

My official position on this: I prefer code readability over specialized (aka clever!) techniques.

I would rather write code that is a little more verbose, and well commented rather than do the same thing in a cryptic or obfuscated manner.

I just had to decipher this RPGLE line of code, because it was just too long and verbose but with no comments whatsoever:

BackDoorExtns = %Trim(BackDoorExtns) + 'CEL' + '000' + %Char(%len(%Trim(cleanCellNumber))) + %char(%DEC(cleanCellNumber:MoreCellPrec:MoreCellDec)) ;

This line of code basically receves an incoming cellphone, from a JSON webservice input, and converts to numeric (with the %DEC BIF) and then puts it in this string (backdoorExtns) but this line of code will BOMB if the cleanCellNumber variable has alphameric values so I changed it to:

RPG Code Snippet clear rpg programming standards//Calculate cellphone number (morecell) and wrap in string with "CEL" control code at start
// JSON inputs the cellphone in incoming character field "cleanCellNumber" but if
// its actually dirty/non-numeric then set to *ZERO
monitor; 
   morecell = %DEC(cleanCellNumber:MoreCellPrec:MoreCellDec); 
   EvalR MskLen = '000' + %Char(%len(%Trim(cleanCellNumber)));
   BackDoorExtns = %Trim(BackDoorExtns) + 
                  'CEL' + MskLen + %char(morecell) ; 
   updateThisReservation = *on; 
on-error 105; 
    morecell = 0; 
endmon;

Yes, I’m guilty of waffling in my comments and sometimes using variable names that make me smile:

If WhiskyEmpty;
  TimeforBed();
endif;

Remember, Software undergoes beta testing just before it’s released.

Beta is Latin for “the program still doesn’t work”.

NickLitten


IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Shameless Trekkie, Belligerent Nerd, Englishman Abroad and Passionate Eater of Cheese and Biscuits. Nick Litten Dot Com is a mixture of blog posts that can be sometimes serious, frequently playful and probably down-right pointless all in the space of a day. Enjoy your stay, feel free to comment and remember: If at first you don't succeed then skydiving probably isn't a hobby you should look into.

Nick Litten

related posts:

Swap Homes and Travel the World – Join Home Exchange
Surf the Web Securely with OPEN DNS
IBM i Software Change Management – CMS vs ALM – What’s in a Name?
Want to learn CL Programming?
{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Get In Touch

I’m always looking for awesome input, feedback and critique!

>

Snug CBD

 20% Discount

I have partnered with SNUG CBD givING you Organic CBD
20% discount code "NL20"