× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On 7/24/2013 7:05 AM, rob@xxxxxxxxx wrote:
I find LEAVE much better than
dowhile &moon='BLUE'
ACTION
MONMSG CPF0000 CHGVAR(&moon) value('PINK')
If &moon<>'BLUE'
...
...
...
6,000 lines of code later
...
...
...
endif
/* someone inserts line here, oopsie */
enddo

Structured programming isn't about operation codes, it's about thinking.
This example is not structured because there's no 6000 line piece of
code that is 'a structure' - a single function. The idea behind
structured programming is to isolate functions from each other for
several reasons:
1) They don't interact in unexpected ways
2) They are reusable
3) They are easy to understand, modify and debug individually
4) They are small enough to keep the whole think in your head at once

Our thoughts become implemented as code, and rules of thumb like the
above help us to organise our thoughts. We're not supposed to value the
rules for the sake of their 'rulieness'. We're supposed to value the
rules because of the assistance they provide when organising our thoughts.

An END 6000 lines away from a DO isn't nearly as helpful as a LEAVE or a
GOTO one line from the test that sets the exit condition. But the
problem with this example isn't LEAVE vs GOTO, it's 6000 lines
masquerading as a single function.

The problem with GOTO isn't breaking out of a structure per se, it's
that you can break out of a structure and go anywhere. One likes to
think of a structure (whether it be a loop or a non-iterating DO group)
as a black box: everything I need to know about it occurs on the
outside. What it does on the inside can be thought of as a single
concept or function as opposed to a dozen individual lines of code.
When one needs an early exit from a single structure, it raises the
question as to whether it really is one structure, or is it two
structures connected via a control block?

Sometimes it's really necessary to leave a loop early; say you're
processing a *OUTFILE and you want to stop when you've found the object
you're looking for. In these circumstances, it doesn't matter a whit if
you exit the loop with a GOTO or a LEAVE. Each operation code will do
the early exit. If one is strict about GOTOing only to the statement
immediately after the loop, there is literally no advantage to either
operation code.

On the other hand, imagine a loop where LEAVEs are sprinkled every few
lines. That loop is nothing like a black box: without a detailed
analysis of all those LEAVE conditions, one would be unable to tell
which parts of the loop would actually execute. So even though the
programmer used the seemingly structured operation code, the fact that
there are many early exits from the loop makes the code itself
non-structured.

It really shouldn't be about the exact operation code. It should be
about whether a given pattern helps one think better.
--buck

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.