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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,99e73f65ea2533b9 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!e39g2000hsf.googlegroups.com!not-for-mail From: =?ISO-8859-1?Q?Santiago_Urue=F1a?= Newsgroups: comp.lang.ada Subject: Re: and then... (a curiosity) Date: Tue, 2 Sep 2008 23:55:05 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <18b41828-bda4-4484-8884-ad62ce1c831d@f36g2000hsa.googlegroups.com> <57qdnfULQ9tzKCHVnZ2dnUVZ_tHinZ2d@comcast.com> <48bd0003$1@news.post.ch> <5bca12f5-b6cc-4e7e-b020-ae0264531156@73g2000hsx.googlegroups.com> NNTP-Posting-Host: 81.35.5.246 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1220424905 28962 127.0.0.1 (3 Sep 2008 06:55:05 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 3 Sep 2008 06:55:05 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: e39g2000hsf.googlegroups.com; posting-host=81.35.5.246; posting-account=Lcd2wAoAAAADW2SqWO5AWY55Q-jjpVWU User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; es-ES; rv:1.9.0.1) Gecko/2008072820 Firefox/3.0.1,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:7617 Date: 2008-09-02T23:55:05-07:00 List-Id: > I don't buy that argument, because the semantics of "A and B and C" > are identical to the semantics of "A and then B and then C" (when A, B, > and C are Boolean variables), so the compiler is free to generate > identical code for both. =A0If efficiency is important in this case, > the compiler should be trained to make it efficient, and the programmer > shouldn't have to worry about it. > Yes, I suppose that's why at AdaCore the convention is to use always short-circuit boolean operators, because gnat can generate the optimized code anyway for just boolean flags. > Your point for (non-inlined) function calls is valid, though -- the > compiler can't be expected to know what's in the function in general. > It is interesting that in Spark the compiler can always optimize these two cases completely, because the functions are always pure. Idea: pragma Profile (Spark) Having said that, even if the performance can be improved, I don't like that rule neither because then when the maintainer sees an "and then" operator she cannot know whether it is just for performance reasons or you really want to avoid some side effects (unless some comments are added). I agree that those micro-optimizations should be done by the compiler, so even if the programmer doesn't write the short-circuit operators when function calls are involved, the compiler should be smart enough to generate lazy evaluation (if the functions are pure). Cheers,