comp.lang.ada
 help / color / mirror / Atom feed
From: "Nick Roberts" <nick.roberts@acm.org>
Subject: Re: Order of logical operations
Date: Fri, 4 Jun 2004 22:09:21 +0100
Date: 2004-06-04T22:09:21+01:00	[thread overview]
Message-ID: <2ic6o2Flfo94U1@uni-berlin.de> (raw)
In-Reply-To: opr8255wqr5afhvo@garuda.mshome.net

"Ed Falis" <falis@verizon.net> wrote in message
news:opr8255wqr5afhvo@garuda.mshome.net...

> On Fri, 04 Jun 2004 18:40:53 GMT, James Van Buskirk
> > I am curious
> > as to how useful short-circuiting logical operators are
> > considered to be in languages such as Ada that have both
> > short-circuiting and non-short-circuiting operators.
>
> The short-circuit forms in Ada are considered to be very
> useful for structural analysis of code during safety
> certification (multiple condition, multiple decision analysis).
> This is because sequentialization of the conditions reduces
> the number of tests that would be necessary compared to
> the simultaneous forms, where all combinations of
> conditions would need to be exercised.
>
> Aside from that, I personally don't have a strong feeling
> about the relative merits, excepting some potential
> performance gains.

Surely it's quite handy to be able to write things like the following?

   A: array (1..10) of Boolean;
   ...
   while i > 0 and then A(i) loop
      ...

The alternatives, such as:

   loop
      exit when i <= 0;
      exit when not A(i);
      ...

are quite a bit clumsier.

As for speed, the situation tends to be complicated if the target
architecture/machine is a typical modern superscalar one. For these, an
optimising compiler is likely to perform some fairly strong transformations,
and the results can be very unexpected. Best speed is likely to depend on
whether the compiler can make the most of special (conditional)
instructions, and often the choice between the short-circuit or ordinary
form will not affect the speed of the emitted code in a predictable manner.

My advice: (a) try to write Ada code to make sense at the level of the
application; (b) if you can (and have time), look at the machine code
emitted; (c) if you can (and have time), perform profiling on the code in
typical execution.

-- 
Nick Roberts





  reply	other threads:[~2004-06-04 21:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <slrncbtfkn.247.tconnors@tellurium.ssi.swin.edu.au>
     [not found] ` <m11xkwd6ct.fsf@macfortran.local>
     [not found]   ` <slrn-0.9.7.4-31741-29330-200406040800-tc@hexane.ssi.swin.edu.au>
     [not found]     ` <40C0208A.80DBE53A@wldelft.nl>
2004-06-04 18:40       ` Order of logical operations James Van Buskirk
2004-06-04 20:06         ` Ed Falis
2004-06-04 21:09           ` Nick Roberts [this message]
2004-06-07 17:00             ` Warren W. Gay VE3WWG
2004-06-07 17:36               ` Ed Falis
2004-06-04 21:37         ` Björn Persson
2004-06-05 10:44         ` Dmitry A. Kazakov
replies disabled

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