From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1094ba,ddafdc033e838b1d X-Google-Thread: 103376,cd51fe79965e9795 X-Google-Attributes: gid1094ba,gid103376,public Path: g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Nick Roberts" Newsgroups: comp.lang.fortran,comp.lang.ada Subject: Re: Order of logical operations Date: Fri, 4 Jun 2004 22:09:21 +0100 Message-ID: <2ic6o2Flfo94U1@uni-berlin.de> References: <40C0208A.80DBE53A@wldelft.nl> X-Trace: news.uni-berlin.de fWCgyN4dXIzoRYBPGHf26w6cHAfsYDNvyLHhLl8Zq+aUfwEg4= X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 Xref: g2news1.google.com comp.lang.fortran:1700 comp.lang.ada:1109 Date: 2004-06-04T22:09:21+01:00 List-Id: "Ed Falis" 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