Home > Archive > Cobol > September 2004 > Re: "Goto statement considered superfluous" (was: If you were inventing C)
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: "Goto statement considered superfluous" (was: If you were inventing C)
|
|
| Howard Brazee 2004-09-28, 3:55 am |
|
On 24-Sep-2004, "JerryMouse" <nospam@bisusa.com> wrote:
> Today, however, any programmer who chooses a technique based on
> micro-efficiency without a compelling reason ("the boss told me to do it
> that way" is one), should be shot.
The definition of "compelling reason" is variable.
And micro-efficiency without significant a cost in understanding or
maintainability doesn't need a compelling reason.
Let's say the following occurs once per day.
Is there a reason to shoot the person who writes the 1st version of this code,
saving 6 assembler moves per day?
MOVE THIS-DAY TO COMPARE-DAY
PERFORM VARYING DAY-INDEX FROM 1 BY 1 UNTIL DAY-INDEX > 7
IF COMPARE-DAY = DAY-OF-WEEK (DAY-INDEX)
PERFORM FOUND-ONE
END-IF
END-PERFORM
PERFORM VARYING DAY-INDEX FROM 1 BY 1 UNTIL DAY-INDEX > 7
MOVE THIS-DAY TO COMPARE-DAY
IF COMPARE-DAY = DAY-OF-WEEK (DAY-INDEX)
PERFORM FOUND-ONE
END-IF
END-PERFORM
| |
| Michael Mattias 2004-09-28, 3:55 am |
| "Howard Brazee" <howard@brazee.net> wrote in message
news:cj9c26$dh9$1@peabody.colorado.edu...
> Is there a reason to shoot the person who writes the 1st version of this
code,
> saving 6 assembler moves per day?
No, but I'd consider shooting the guy who wrote the second one, which does
not terminate the lookup (EXIT PERFORM) when COMPARE-DAY =
DAY-OF-WEEK(DAY-INDEX) and performs FOUND-ONE.
Curious how sometimes the most obvious optimizations are those most easily
missed.
MCM
>
> MOVE THIS-DAY TO COMPARE-DAY
> PERFORM VARYING DAY-INDEX FROM 1 BY 1 UNTIL DAY-INDEX > 7
> IF COMPARE-DAY = DAY-OF-WEEK (DAY-INDEX)
> PERFORM FOUND-ONE
> END-IF
> END-PERFORM
>
>
> PERFORM VARYING DAY-INDEX FROM 1 BY 1 UNTIL DAY-INDEX > 7
> MOVE THIS-DAY TO COMPARE-DAY
> IF COMPARE-DAY = DAY-OF-WEEK (DAY-INDEX)
> PERFORM FOUND-ONE
> END-IF
> END-PERFORM
| |
| Howard Brazee 2004-09-28, 3:55 am |
|
On 27-Sep-2004, "Michael Mattias" <michael.mattias@gte.net> wrote:
> code,
>
> No, but I'd consider shooting the guy who wrote the second one, which does
> not terminate the lookup (EXIT PERFORM) when COMPARE-DAY =
> DAY-OF-WEEK(DAY-INDEX) and performs FOUND-ONE.
>
> Curious how sometimes the most obvious optimizations are those most easily
> missed.
I thought about that when I wrote this example - and decided that my point was
made better by leaving obvious ways to optimize the code without adding
significant obfuscation/cost.
It is interesting though that this "obvious" optimization is less obvious at
closer examination. I don't know how efficient the compiler is, for instance,
and I do know that adding an extra check does add some overhead. While my
assumption is the same as yours - it is obvious that coding an early exit is
more efficient than repeating the loop, I also see that 3 1/2 more iterations
isn't a big cost, and adding a comparison where a maintenance programmer might
make a mistake isn't quite as efficient as it looks.
Still, we both code for efficiency when the cost appears low.
|
|
|
|
|