× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



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.


&#8203;No I didn't, I didn't catch this line
&#8203;

&#8203;&#8203;
&#8203;elseif
&#8203;&#8203;
%check(
&#8203;&#8203;
content: chr) > 0;&#8203;

&#8203;Which is handling the distinct requirement.&#8203;



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?



&#8203;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:

&#8203;
&#8203;elseif
&#8203;&#8203;NewDistinctChar(
&#8203;
content: chr
&#8203;);

With NewDistinctChar() simply being a
return &#8203;
&#8203;
%check(
&#8203;&#8203;
content: chr) > 0
&#8203;;

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. :)
&#8203;

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.