|
From: John R. C. <jo...@we...> - 2005-08-20 16:19:33
|
On Saturday 20 August 2005 02:01 pm, Jim Morcombe wrote:
> John
>
> I've got to disagree with you.
>
> The EVALUATE TRUE allows a whole heap of spagetti-coded IF, THEN, ELSEs
> to be replaced by a nice easy-to-follow slab of structured code. Just
> because Cobol 74 programmers never learnt new tricks doesn't doesn't
> mean they weren't worth learning.
>
> The EVALUATE TRUE improves program structure and anything that improves
> program structure needs to be supported.
>
> Jim
Well I have four problems with that.
First I don't understand EVALUATE TRUE.
Second I have four texts on my desk which
allegedly cover COBOL 85. Only the newest of these (pub date
2000) gives an example of EVALUATE TRUE and it is identical in
effect to a straight EVALUATE. The word TRUE could be omitted.
Two of these books represent the entire COBOL library of the
local community college.
Third since I don't know what it does obviously I have no
knowledge of a situation where it would be necessary or even
useful. Perhaps you can offer one.
I cannot offer an example of using EVALUATE TRUE because frankly
I don't understand it. But here is a fragment from a real
program written 25 years ago that I converted to EVALUATE form:
(example 1.)
EVALUATE SCREEN-FLAG
WHEN "L" PERFORM 150-INPUT-SCREEN
WHEN "E" PERFORM 200-CLEAR-FIELDS
PERFORM 400-ENTER-DATA
WHEN "C" PERFORM 400-ENTER-DATA
WHEN "O" PERFORM 405-SINGLE-ENTRY
WHEN "S" PERFORM 300-SHOW-SCREEN
WHEN "D" PERFORM 200-CLEAR-FIELDS
END-EVALUATE
EXIT PROGRAM.
-----------and here is an alternative form that I think is more
readable:
(example-2.)
IF LOAD PERFORM 150-INPUT-SCREEN.
IF ENTER-ALL PERFORM 200-CLEAR FIELDS
PERFORM 400-ENTER DATA.
IF CHANGE-ALL PERFORM 400-ENTER DATA.
IF CHANGE-ONE PERFORM 405-SINGLE-ENTRY.
IF SHOW PERFORM 300-SHOW-SCREEN.
IF CLEAR PERFORM 200-CLEAR-FIELDS.
EXIT PROGRAM.
Why no ELSE IF? Because the field SCREEN-FLAG can only hold one
value at a time. Therefore fall-through logic works. This would
be true for any real world WHEN type test.
Finally the ELSE IF logic can also be used to good effect. This is a
more general construct than example-2. IMO it is not spaghetti code. YMMV.
(example-3.)
IF LOAD PERFORM 150-INPUT-SCREEN
ELSE IF
ENTER-ALL PERFORM 200-CLEAR FIELDS
PERFORM 400-ENTER DATA
ELSE IF
CHANGE-ALL PERFORM 400-ENTER DATA
ELSE IF
CHANGE-ONE PERFORM 405-SINGLE-ENTRY
ELSE IF
SHOW PERFORM 300-SHOW-SCREEN
ELSE IF
CLEAR PERFORM 200-CLEAR-FIELDS.
EXIT PROGRAM.
The word WHEN has been replaced by ELSE IF. The effect is the
same.
Examples 2 and 3 use condition names. Example 1 doesn't.
Why? because condition names in a WHEN statement
gave an error in Tiny COBOL. Now that is something that needs
fixing.
John Culleton
|