I agree about procedures, but if a procedure fits on one screen, and this on does, I generally don't try to break it down further. I also try to minimize global variables. I prefer to keep one liners like that in the procedure that is calling it, unless I need it again. But if I do turn it into a procedure, I then pass it all the parameters it needs. It is a real balancing act. The problem with globals is that they make it harder to move a procedure out to a service program. Thus I tend to reserve globals for things like screen formats and indicators. The thought is that display files are generally not shared between programs, thus the procedures that handle them will rarely be moved to a service program. OO languages make all this a bit easier.
Mark Murphy
STAR BASE Consulting, Inc.
mmurphy@xxxxxxxxxxxxxxx
-----Charles Wilt <charles.wilt@xxxxxxxxx> wrote: -----
To: "RPG programming on the IBM i (AS/400 and iSeries)" <rpg400-l@xxxxxxxxxxxx>
From: Charles Wilt <charles.wilt@xxxxxxxxx>
Date: 07/01/2016 01:38PM
Subject: Re: Clarified interview question (programming puzzle)
On Fri, Jul 1, 2016 at 11:44 AM, Mark Murphy/STAR BASE Consulting Inc. <
mmurphy@xxxxxxxxxxxxxxx> wrote:
Did you try it? I did, and all of the test cases in John's post pass.
​No I didn't, I didn't catch this line
​
​​
​elseif
​​
%check(
​​
content: chr) > 0;​
​Which is handling the distinct requirement.​
As for procedures, this is a single procedure were the only duplicated
code is in the block mentioned above. I guess I could have broken that out.
Otherwise I would be splitting things up for the sake of splitting them up?
​Procures aren't just for removing duplicated code. They can make the code
more self documenting and easier to follow. Case in point the above code
could have been:
​
​elseif
​​NewDistinctChar(
​
content: chr
​);
With NewDistinctChar() simply being a
return ​
​
%check(
​​
content: chr) > 0
​;
I'm a big fan of being able to glance at the code and being able to
understand what's going on. IMHO, code inside nested if's is something to
avoid as it is not conducive to doing that.
From a philosophical point of view, I expect RPG IV code to be using
procedures. Tasks should be broken down into smaller chunks.
Might explain my fondness for top-down development. :)
​
As an Amazon Associate we earn from qualifying purchases.