Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: "Goto statement considered superfluous" (was: If you were inventing C)
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 cod
e,
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

Report this thread to moderator Post Follow-up to this message
Old Post
Howard Brazee
09-28-04 08:55 AM


Re: "Goto statement considered superfluous" (was: If you were inventing C)
"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



Report this thread to moderator Post Follow-up to this message
Old Post
Michael Mattias
09-28-04 08:55 AM


Re: "Goto statement considered superfluous" (was: If you were inventing C)
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 doe
s
> 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 w
as
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 instan
ce,
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 iteration
s
isn't a big cost, and adding a comparison where a maintenance programmer mig
ht
make a mistake isn't quite as efficient as it looks.

Still, we both code for efficiency when the cost appears low.

Report this thread to moderator Post Follow-up to this message
Old Post
Howard Brazee
09-28-04 08:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Cobol archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:33 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.