Re: how?
Re: how?
- Subject: Re: how?
- From: "Mark J. Reed" <email@hidden>
- Date: Thu, 14 Jan 2010 09:34:53 -0500
There's absolutely nothing wrong with exiting a loop in the middle.
The problem comes when you have multiple exit points with no clear
relationships, or goto's that take you out of the loop to somewhere
other than the first statement after the end of the loop. One "exit
loop" does not spaghetti-code make. Some folks tend to forget the
original context in which "Goto Considered Harmful" was written, how
badly unstructured most code was. And even then, Dijkstra wasn't
trying to issue a blanket prohibition.
I am a fan of making such exits stand out visually with whitespace -
and outdenting, when not using a significant-whitespace language - but
as long as it's clear what's happening, it's all good.
Now, if an internal break or exit or return or whatever is the only
way out of the loop, then you should make that obvious by using the
"do forever" form of the loop: "repeat" by itself, or "for (;;)", or
"while True:", or whatever. When the reader sees that, they'll know
to look for an exit in the body.
The problem with the example is that it doesn't do that; it appears to
have a normal condition at the top of the loop, whose trigger the
reader seeks within the body of the loop, but their search is in vain.
Misleading code is never good (unless, of course, it's a contest
whose goal is to mislead the reader of the code...). If the intent is
documentation, then it's better to just write actual documentation:
repeat -- forever until we get valid input
As far as programming tricks and techniques, there's nothing new under
the sun. (Well, OK, maybe the Schwartzian Transform was. :)) But
there's no harm in acknowledging someone for popularizing a particular
trick in a particular context. Spreading knowledge is as important
for progress as discovering it in the first place.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden
References: | |
| >Re: how? (From: Adam Morris <email@hidden>) |
| >Re: how? (From: Chris Page <email@hidden>) |
| >Re: how? (From: LuKreme <email@hidden>) |