Is it okay if I use a lot of while(true) loops?

G

Gennaro Prota

On 23/08/2010 14.24, Francesco S. Carta wrote:
[...]
A penalty of 5K€ per minute of downtime? What was that, if I can be
indiscreet?

Likely something for telecommunication, anywhere else than
Italy. The same should probably be true for anything that would
stop or delay a factory's production (think e.g. of a car
factory). But, again, not in Italy.

In fact, I suspect that these are the only cases where you'll
see some quality software (because if you make an error, you
pay. And no, it's not a weird insect that infiltrated the
system: it's an error, and *you* made it). Outside of that,
"they" seem all to be accustomed to the "this software is
provided as is, without any warranty express or implied"
pseudo-philosophy (you take all the risks, even if you paid
1000€ for a single copy). Except for telling otherwise in all
the marketing hype.
 
J

James Kanze

On Aug 21, 4:07 pm, "Francesco S. Carta"<[email protected]> wrote:
[...]
(On a number of these projects, we had contractual penalties for
down time---on the order of 5000 Euro per minute. Given that it
took 2 or 3 minutes to read the initial configuration from disk,
stopping the application would cost a minimum of 10 or 15
thousand Euros.)
A penalty of 5K€ per minute of downtime? What was that, if I can be
indiscreet?

On my case, telecoms. The main backbone router for calls
entering and leaving central Germany. Or later, on an internal
project (so no real payment, but it did affect my boss' future
in the company), dynamic IP allocation for a wireless network.

Other projects have used different technics for motivation: on
a locomotive brake system, it was required that the head of
software development be present on the locomotive during
acceptance tests (which involved actually trying to apply the
brakes at speed, and did entail some risk if the program
failed).
In such a case, I suppose forcing the admin to reboot the
machine by not providing any "orderly shutdown" command seems
indeed The Way To Go ;-)

You provide an orderly shutdown command if it can do anything.
On a lot of such systems, however, there's a hot backup waiting
to take over, and it detects the absense of any activity on your
machine, so just rebooting triggers it, and you don't (and
shouldn't) do anything else.
 
G

Gennaro Prota

On 23/08/2010 13.59, James Kanze wrote:
[...]
One thing: *if* you want to defend this way of writing things,
the line containing the break must be immediately visible.
In some other language, one might imagine:

double sum = 0.0;
cout << explanation << endl;
LOOP
double number = numberFromUser( "Number? " );
UNTIL number == 0.0;
sum += number;
END

Just curious: is the construct from a real language, or did you
invent it? It seems odd that UNTIL does not end the loop body
:)
 
J

James Kanze

On 23/08/2010 13.59, James Kanze wrote:
[...]
One thing: *if* you want to defend this way of writing things,
the line containing the break must be immediately visible.
In some other language, one might imagine:
double sum = 0.0;
cout << explanation << endl;
LOOP
double number = numberFromUser( "Number? " );
UNTIL number == 0.0;
sum += number;
END
Just curious: is the construct from a real language, or did you
invent it? It seems odd that UNTIL does not end the loop body
:)

It's a real language, in the sense that I had an interpreter for
it and could write and execute code in it on my machine. But
it's a language I invented and implemented for experimental
purposes. And I later changed it so that the WHILE, UNTIL and
FOR clauses had to immediately follow the LOOP keyword.

My point here, however, isn't so much whether it's a good idea
to be able to exit the loop in the middle; I don't think it is,
but there are certainly worse sins. The point is that if you do
so, it had better be very, very visible. Having a special
keyword (with keywords all caps, so they stick out), and
indenting it like the rest of the loop control statements (and
requiring it to be at the outermost level in the loop, and not
embedded in ten levels of if, and only allowing one) goes a long
way to making it almost acceptable; at least you can see the
irregularities at first glance (and be aware, for example, that
the loop invariants established by the clause may not hold for
the first half of the loop, the first time through).
 
P

Phlip

http://thedailywtf.com/Articles/Masquerading-as-a-Loop.aspx

Joe "M2tM" Smith,
"I encountered a conditional masquerading as a loop."

"Thankfully, the fellow responsible is 'no longer with us', and I
suppose this type of code stands as silent testament to why. This
interesting loop is only created so the break keyword can be used as
an elaborate GOTO."

bool bCreateModel = false;
for (;;)
{
if (!pModel)
{
bCreateModel = true;
break;
}

if (asModelParts.GetSize() != asModelPartsToLoad.GetSize())
{
bCreateModel = true;
break;
}

for (UINT32 i = 0; i < asModelPartsToLoad.GetSize(); ++i)
{
if (asModelPartsToLoad != asModelParts)
{
bCreateModel = true;
break;
}
}

break;
}
 
B

Balog Pal

James Kanze said:
My point here, however, isn't so much whether it's a good idea
to be able to exit the loop in the middle; I don't think it is,
but there are certainly worse sins. The point is that if you do
so, it had better be very, very visible.
Sure.

Having a special
keyword (with keywords all caps, so they stick out), and
indenting it like the rest of the loop control statements (and
requiring it to be at the outermost level in the loop, and not
embedded in ten levels of if, and only allowing one) goes a long
way to making it almost acceptable; at least you can see the
irregularities at first glance (and be aware, for example, that
the loop invariants established by the clause may not hold for
the first half of the loop, the first time through).

And do we really have to mutilate the language or invent one to get that?
I use editors with syntax-coloring from whatever. Each have category
'keyword'. So every break, continue, return in the loop body stands out
nicely. All by itself. Especially if you use blank lines where it make
sense. :)

IME healthy C++ usage is light on keywords, so there's hardly a problem. If
there is a swamp of them the shit is probably deep for other reasons.
 
B

Balog Pal

Phlip said:
Joe "M2tM" Smith,
"I encountered a conditional masquerading as a loop."

"Thankfully, the fellow responsible is 'no longer with us', and I
suppose this type of code stands as silent testament to why. This
interesting loop is only created so the break keyword can be used as
an elaborate GOTO."

bool bCreateModel = false;
for (;;)
{
if (!pModel)
{
bCreateModel = true;
break;
}

if (asModelParts.GetSize() != asModelPartsToLoad.GetSize())
{
bCreateModel = true;
break;
}

for (UINT32 i = 0; i < asModelPartsToLoad.GetSize(); ++i)
{
if (asModelPartsToLoad != asModelParts)
{
bCreateModel = true;
break;
}
}

break;
}


Sigh. No one told the guy to use

do {
} while(0);

for the purpose, that is the 'idiomatic' way.
 
F

Francesco S. Carta

Phlip said:
Joe "M2tM" Smith,
"I encountered a conditional masquerading as a loop."

"Thankfully, the fellow responsible is 'no longer with us', and I
suppose this type of code stands as silent testament to why. This
interesting loop is only created so the break keyword can be used as
an elaborate GOTO."

bool bCreateModel = false;
for (;;)
{
if (!pModel)
{
bCreateModel = true;
break;
}

if (asModelParts.GetSize() != asModelPartsToLoad.GetSize())
{
bCreateModel = true;
break;
}

for (UINT32 i = 0; i < asModelPartsToLoad.GetSize(); ++i)
{
if (asModelPartsToLoad != asModelParts)
{
bCreateModel = true;
break;
}
}

break;
}


Sigh. No one told the guy to use
do {
} while(0);

for the purpose, that is the 'idiomatic' way.


I really hope you're kidding.

This is the idio+make+ way:

#define BREAKABLE(CODE) do { CODE } while (!~1)

BREAKABLE(
// put code here
);

I know, it costs more time to the coder, but saves a lot to the manager!
 
P

Phlip

"Phlip" <[email protected]>


Joe "M2tM" Smith,
"I encountered a conditional masquerading as a loop."
"Thankfully, the fellow responsible is 'no longer with us', and I
suppose this type of code stands as silent testament to why. This
interesting loop is only created so the break keyword can be used as
an elaborate GOTO."
   bool bCreateModel = false;
   for (;;)
   {
       if (!pModel)
       {
           bCreateModel = true;
           break;
       }
       if (asModelParts.GetSize() != asModelPartsToLoad.GetSize())
       {
           bCreateModel = true;
           break;
       }
       for (UINT32 i = 0; i < asModelPartsToLoad.GetSize(); ++i)
       {
           if (asModelPartsToLoad != asModelParts)
           {
               bCreateModel = true;
               break;
           }
       }

       break;
   }

Sigh.  No one told the guy to use

do {

} while(0);

for the purpose, that is the 'idiomatic' way.  


But at least Java doesn't have that eeeevil 'goto'! Nope!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top