On 14/08/2016 2:57 AM, Paul Gilmartin wrote:
On Sat, 13 Aug 2016 09:02:28 -0500, Bill Woodger wrote:
This can be rewritten as
while (true)
read value
if (value == sentinel) break;
process value
Yet I prefer expression-oriented languages that allow constructs such as:
while read value && [ value != sentinel ]; do
process value
done
I prefer object-oriented languages that support exceptions with
constructs such as:
try
{
FooInputFileinput( indsn );
BarOutputFileoutput( outdsn );
while ( input.read() )
{
// do something
}
}
catch (exception &e )
{
cout <<"Error: " << e.what();
}
Of course, exceptions are just like gotos but used judiciously can make
code much easier to read and write.
But, yes, if the condition is a little more complicated, it's better to
encapsulate
it in a function. Legibility should be the deciding concern: which constructs
impels fewer saccades by the reader?
-- gil
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN