Should RPG code be long form or short form?
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:
//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”.
Thank you Nick for pointing to a main concern: we programming with maintenance in mind?