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.
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”.
IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Alpha Nerd 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 in the words of the most interesting man in the world: Stay thirsty my friend.
Don’t hardcode library names in your TURNOVER SQL source #youbigsilly
How to Install IBM Access Client Solutions (ACS)
IBM i Data Obfuscation – Making Data Foggy Murky and Squinty
How to rename Fresche (BCD) Presto Library – XL_PRESTO
What is AS400 modernization?
IBM i ACS 5250 EMULATOR FONT – and other ridiculous mumbo jumbo
IBM i SQL statement to convert or compare hundred year date format
How to compare ‘100 Year Date’ to a Timestamp – aka – Weird AS400 iSeries Date formats
Modernize AS400 iSeries Queries – Convert to IBM i SQL