The use of /copy and the application of company standards (like you must
use copybooks for common declares) eliminates the "each program has one
change" and the use of different names for the same value. Imbedded
literals, within the executable portion of a program, is to be avoided in
my opinion.
Bruce Vining
"Bob P. Roche" <BRoche@xxxxxxxxxxxxxxxxx>
Sent by: rpg400-l-bounces@xxxxxxxxxxxx
05/03/2007 10:13 AM
Please respond to
RPG programming on the AS400 / iSeries <rpg400-l@xxxxxxxxxxxx>
To
RPG programming on the AS400 / iSeries <rpg400-l@xxxxxxxxxxxx>
cc
Subject
Re: Benefits of declaring literals in D-specs
One of the reasons I remember being told to do this is what if they change
account types. The business expanded or some VP has a "wonderful new
system". Account 32 is now Account 132. In each program you only need to
update one place and recompile.
Alan Shore <AlanShore@xxxxxxxx>
Sent by: rpg400-l-bounces@xxxxxxxxxxxx
05/03/2007 09:58 AM
Please respond to
RPG programming on the AS400 / iSeries <rpg400-l@xxxxxxxxxxxx>
To
RPG programming on the AS400 / iSeries <rpg400-l@xxxxxxxxxxxx>
cc
Subject
Re: Benefits of declaring literals in D-specs
Brian - I agree with your thought process, but over time, I have found
there is one problem with this idea.
To you, Acct_type 32 is defined as DEAD-BEAT, but to someone else
Acct_type
32 is defined as DEFUNCT_TYPE, therefore a search on DEFUNCT will result
in
nothing found, and therefore a search of 32 is then required.
By itself - no great shakes, but somewhat irksome.
Alan Shore
NBTY, Inc
(631) 244-2000 ext. 5019
AShore@xxxxxxxx
"If you're going through Hell, keep going" - Winston Churchill
rpg400-l-bounces@xxxxxxxxxxxx wrote on 05/03/2007 10:30:28 AM:
Named literals avoid the magic number anti-pattern. What does these
statements mean:
if status_code = 32
return
endif
if acct_type = 32
...
endif
What the heck is 32? Are both 32's the same thing?
Compare to this
d EXIT_KEY_PRESSED C 32
d DEAD_BEAT C 32
...
if status_code = EXIT_KEY_PRESSED
return
endif
if acct_type = DEAD_BEAT
...
endif
Now the code is much clearer. And, if you want to locate code that
processes dead-beat accounts, it is ead to find. If you search for 32,
you
have to examine each reference and decide if it is account type or some
function key thing.
As an Amazon Associate we earn from qualifying purchases.