Dave Kahn wrote:

But ITER and LEAVE are really GOTO in a cage. They are extremely
useful for practical programming but they are in a sense dirty tools
that violate the idea of a single exit and entry point.

ANYGHING, on some level, that introduces iteration or choice into program flow, is (at least in part) "GOTO in a cage."

Niklaus Wirth, for all his genius, had (at least when he invented Pascal) an incomplete and highly prejudiced understanding of iterative structures. When he invented Modula-2, his understanding was much better, and much less biased, because by then he had recognized that there are plenty of cases in the real world where an iterative structure shouldn't run to completion unless something goes wrong, and thus he added "leave" functionality.

Consider this situation: You are running through a table with a hundred thousand entries, and it is neither indexed nor sorted. Completely random. By the strict "single entry, single exit" rule, you HAVE to look at all of the entries, every time, whether the one you're looking for is the first one or the last one, and if you need values from the matching entry outside your loop, you need to make working copies. Lots of unnecessary complexity, a structure that's counter-intuitive to what you're trying to do, and (on average) half your iterations will be unnecessary.

But if you go to a "single entry, single exit, with leave" rule, you end up with a simpler structure that more accurately reflects what it's actually doing, and NO unnecessary iterations.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
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.