Re: Breaking from the middle of a loop (C++)
- From: Anders Karlsson <anders43@xxxxxxxx>
- Date: Thu, 31 Jan 2008 21:14:15 +0800
On Wed, 30 Jan 2008 21:56:17 -0500, "Daniel T."
<daniel_t@xxxxxxxxxxxxx> wrote:
I personally don't like the style. Yes, I have read the rational from
several authors but that isn't why I have a problem with it. My feelings
about it were born out of the times I have spent debugging other
people's code. People who used such multiple exits almost
indiscriminately. It became a truism for me that when I needed to find a
bug, the first place I would look is inside blocks of code that had
multiple exits.
I don't think the multiple exit is the real problem, it is the lengthy
function that people then sprinkle with lots of exits.
I personally prefer the direct exit as in <1> as it is clearer, but
only in smaller functions. Having it in code I read today wouldn't
have helped, the programmer had written the function like this:
int foo()
{
int ret=0;
stmt;
stmt;
ret=stmt;
if (ret == 0 ) {
stmt;
stmt;
...
if (expr)
ret = 1;
}
if (ret == 0 ) {
stmt;
stmt;
...
if (expr)
ret = 1;
}
ad infinitum
(actually several hundred lines to be more precise)
and this just to avoid multiple exits... that was hard to read but it
was more due to the fact that the function was so bloody long.
I also am a bit skeptic to exceptions and use them sparingly for
detection exceptions and not really for recovery.
/ajk
--
Always acknowledge a fault. This will throw those in authority off their guard and give you an opportunity to commit more.
/Mark Twain
.
- Prev by Date: Socket Problem
- Next by Date: Re: general algorithm + ackermann question
- Previous by thread: Socket Problem
- Next by thread: Application of Various Programming Languages?
- Index(es):
Relevant Pages
|