comp.lang.ada
 help / color / mirror / Atom feed
* RE: short-circuit control forms
@ 2001-06-20 19:50 Beard, Frank
  2001-06-20 20:35 ` Ted Dennison
                   ` (2 more replies)
  0 siblings, 3 replies; 36+ messages in thread
From: Beard, Frank @ 2001-06-20 19:50 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'


-----Original Message-----
From: James A. Krzyzanowski [mailto:James_A_Krzyzanowski@raytheon.com]

> Our software engineers believe that using short-circuit control forms
> will make our software more efficient (speed-wise).  So, they have been
> replacing every "and" with "and then" and every "or" with "or else".

I've heard this before, as well.  And it makes sense, unless there is
some problem or inefficiency with generating the underlying branch
statements.

It seems to me that the "and" and "or" should have been implemented
in the short circuit form to begin with, instead of requiring 
"and then" and "or else".  As soon as one of the conditions is FALSE
for "and" or TRUE for "or", there is no need to check the remaining
arguments.

Frank Beard



^ permalink raw reply	[flat|nested] 36+ messages in thread
* RE: short-circuit control forms
@ 2001-06-20 22:20 Beard, Frank
  2001-06-21 14:58 ` Marin David Condic
  2001-06-21 17:11 ` Warren W. Gay VE3WWG
  0 siblings, 2 replies; 36+ messages in thread
From: Beard, Frank @ 2001-06-20 22:20 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'


-----Original Message-----
From: Marin David Condic [mailto:marin.condic.auntie.spam@pacemicro.com]

> Better to have the short-circuit things optional so you can manually
enable
> and disable the behavior as needed. Most of the time the extra efficiency
is
> likely to be a) too small to sweat and b) not an issue because it isn't a
> hard realtime system.

Well, the argument could be made that if your second condition raised an
exception then your unit testing was insufficient (and yes I know unit 
tests can't always catch everything).  And as a general rule, it's a bad
idea to write functions with side effects, unless you have some glaring 
necessity to do so.  Most, if not all, of the conditional statements that
I've written fall into the "and then" and "or else" category.

But as a point Marin has already made, I don't even worry about any of
these cases unless there is some runtime penalty.  In most cases, I
just use "and" and "or" because the code is cleaner looking.

I still would have preferred the short-circuit to be the default. 
"And then" could have meant, "if this part is true then check the
next part".  Or change "and then" to "and also".

  if A and also B then

"Or else" is confusing either way.

All that aside, I can live with the way it is currently.  It's not a
big deal.  I was just stating a preference.  And as I said, I don't
actually worry about it until it becomes a problem.

Frank Beard



^ permalink raw reply	[flat|nested] 36+ messages in thread
[parent not found: <B6A1A9B09E52D31183ED00A0C9E0888C469BC4@nctswashxchg.nctswash.navy.mil>]
* short-circuit control forms
@ 2001-06-20 19:23 James A. Krzyzanowski
  2001-06-20 20:15 ` Ted Dennison
                   ` (3 more replies)
  0 siblings, 4 replies; 36+ messages in thread
From: James A. Krzyzanowski @ 2001-06-20 19:23 UTC (permalink / raw)


Looking for expert opinions...

We have a company standard which states:
"standard => Use short-circuit control forms to specify the order of
             conditions when the failure of one condition means that
             the other condition will raise an exception.
 guideline => Avoid short-circuit control forms otherwise."

Our software engineers believe that using short-circuit control forms
will make our software more efficient (speed-wise).  So, they have been
replacing every "and" with "and then" and every "or" with "or else".

We use Rational Apex and a Rational Representative sent correspondence
basically saying that their compiler will NOT optimize plain "and" and
"or" to behave as though the best "and then" and "or else" order has
been specified.

The reason for our standard on this topic is because we expected the
compiler to be smarter than the software engineer when it comes to
specifying an order of conditions.  This is also consistent with
Ada 95 Quality and Style: Guidelines for Professional Programmers.

If using "and then" and "or else" will make our software quicker, and
then the compiler doesn't optimize any better anyway, does anybody have
a good reason why we should NOT use short-circuit control forms?

-- 
---------------------------------------------------------------------------
         James A. Krzyzanowski - Staff Software Engineer - AFATDS       %c%
     Raytheon Systems Company * Fort Wayne, IN 46808 * (219) 429-6446   cus
                 mailto:James_A_Krzyzanowski@raytheon.com               %s%
---------------------------------------------------------------------------



^ permalink raw reply	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2001-06-26 15:48 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-20 19:50 short-circuit control forms Beard, Frank
2001-06-20 20:35 ` Ted Dennison
2001-06-20 22:32   ` Jeffrey Carter
2001-06-21  1:18     ` Mark Lundquist
2001-06-21 17:05       ` Jeffrey Carter
2001-06-21 14:31     ` Wes Groleau
2001-06-20 23:45   ` Dale Stanbrough
2001-06-20 20:57 ` Marin David Condic
2001-06-21  7:31 ` Keith Thompson
  -- strict thread matches above, loose matches on Subject: below --
2001-06-20 22:20 Beard, Frank
2001-06-21 14:58 ` Marin David Condic
2001-06-21 17:11 ` Warren W. Gay VE3WWG
2001-06-21 17:49   ` Marin David Condic
     [not found] <B6A1A9B09E52D31183ED00A0C9E0888C469BC4@nctswashxchg.nctswash.navy.mil>
2001-06-20 21:10 ` Wilhelm Spickermann
2001-06-20 19:23 James A. Krzyzanowski
2001-06-20 20:15 ` Ted Dennison
2001-06-20 20:47 ` Marin David Condic
2001-06-20 22:23 ` Jeffrey Carter
2001-06-21  0:45   ` Al Christians
2001-06-21 15:06     ` Wes Groleau
2001-06-21 15:46       ` Al Christians
2001-06-21 18:28         ` Wes Groleau
2001-06-21 18:51         ` Marin David Condic
2001-06-22 12:17           ` Marc A. Criley
2001-06-22 14:55             ` Marin David Condic
2001-06-22 20:58   ` Robert Dewar
2001-06-22 21:49     ` Ted Dennison
2001-06-22 22:58     ` Jeffrey Carter
2001-06-23  0:38       ` Larry Kilgallen
2001-06-23 17:34       ` Simon Wright
2001-06-26 15:48       ` Wes Groleau
2001-06-25 17:00     ` Wes Groleau
2001-06-21  0:13 ` Mark Lundquist
2001-06-21  0:55   ` Al Christians
2001-06-21 12:39   ` Larry Kilgallen
2001-06-21 15:02   ` Wes Groleau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox