On 8/9/2016 9:11 AM, Richard Reeve wrote:
You raise a valid point and have made me a bit ashamed of myself. I'm
one of those old school grumps (well, maybe I'm not a grump) but I'm old
school. I need to force myself to look at better ways of doing things.
Can you suggest tutorials or books that will encourage me to become a true
FREE/ILE rpg guy?
I learnt RPG by example; by working on code in an existing code base. A
code base written a generation before me. So my initial RPG was a lot
like you posted. What helped me break out of that was to learn and use
another language. I still learnt by example, but the examples were 2
generations newer than my RPG examples.
Eventually, I found myself 'borrowing' C patterns and implementing them
in my RPG. What I ultimately found to be the most value was learning
how to think better. 'Better' of course is always in the eye of the
beholder, but for me, right now it means:
1) Few or no global variables - sub-procedures rule!
2) Logic that _does something_ is distinct from logic that _decides
something_. So instead of
cust chain customer
if %found()
if ar_balance > cr_limit
...100 lines that handle processing the order
else
...30 lines that handle denying the order
endif
endif
I might write
if is_credit_sufficient(cust: cr_limit)
process_order()
else
deny_order()
endif
3) Write testable functions. I should be able to test individual
sub-procedures outside of the program they will ultimately go into.
4) Think about error conditions first. Everything will fall over. Plan
for it up front. In the above code, what should happen if the CHAIN to
CUSTOMER finds no record? What if it fails due to a read trigger
failure, or RCAC denial?
5) Read programming books / articles / blogs / columns. I recommend
Steve McConnell's 'Code Complete' even though a lot of it uses OO as
examples. There are lots of great general purpose ideas there. The
idea is to get exposed to different ideas, different ways to think.
Once my thinking got better, I found ways to express that thought in my
RPG code. I believe this is a better approach than to try to improve
the form of my code in order to make my thinking better, but there is a
deep connexion between the two which cannot be denied.
As an Amazon Associate we earn from qualifying purchases.