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-Thread: 103376,99e73f65ea2533b9 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder.news-service.com!newsfeed00.sul.t-online.de!t-online.de!newsfeed-0.progon.net!progon.net!news-zh.switch.ch!switch.ch!news.ip-plus.net!newsfeed.ip-plus.net!news.post.ch!not-for-mail From: Martin Krischik Newsgroups: comp.lang.ada Subject: Re: and then... (a curiosity) Date: Tue, 02 Sep 2008 08:53:58 +0200 Organization: Swisscom IP+ (post doesn't reflect views of Swisscom) Message-ID: <48bce306$1@news.post.ch> References: <18b41828-bda4-4484-8884-ad62ce1c831d@f36g2000hsa.googlegroups.com> <874p53bij6.fsf@willow.rfc1149.net> <94cc1ce3-59d1-41fa-9167-f3b60ddd2835@a1g2000hsb.googlegroups.com> <48bba264$1@news.post.ch> NNTP-Posting-Host: 194.41.146.1 Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: atlas.ip-plus.net 1220338443 18338 194.41.146.1 (2 Sep 2008 06:54:03 GMT) X-Complaints-To: abuse@ip-plus.net NNTP-Posting-Date: Tue, 2 Sep 2008 06:54:03 +0000 (UTC) User-Agent: Thunderbird 2.0.0.16 (Windows/20080708) In-Reply-To: X-Original-NNTP-Posting-Host: w03duo.pnet.ch X-Original-Trace: 2 Sep 2008 08:53:58 +0100, w03duo.pnet.ch Xref: g2news1.google.com comp.lang.ada:1859 Date: 2008-09-02T08:53:58+02:00 List-Id: Ray Blaak schrieb: > Martin Krischik writes: >> Actually it is good example - for both: >> >> 1) Log to both Disk and Network and return true if at least one was >> successful: >> >> Log_To_Network (Message) or Log_To_Disk (Message) >> >> 2) Log to Network and if that fails log to Disk and return true if at >> least one was successful: >> >> Log_To_Network (Message) or else Log_To_Disk (Message) >> >> And it shows nicely the why there are two: The programmer can decide >> which behaviour he / she wants. > > My problem is not with the theoretical elegance as such, but rather that "or" > vs "or else" is not immediately clear to me. > As a multi-language programmer, I am really really used to thinking of boolean > or as "if one is true we don't care about the other". Funny I am not - probably because my first languages where Basic and Pascal - and Basic and Pascal do not guarantee short cut boolean. Modern Basic and Pascal dialects might have it but it is not guaranteed in the language itself. > This instinct is > reenforced both from the current popular languages as well as from formal > proof styles in programming methodology. When I was at Polytechnic first language was PL/1, second Pascal and therefore methodology was different. i.E. Don't rely on the execution order of boolean expressing. > So, I don't like relying the execution of both disjuncts. Sure, I could use > "or else" consistently, but I like thinking of boolean or as good old regular > boolean or. They are not necessarily both executed with plain old OR and AND either. Plain old OR and AND leaves all options open to the optimizer: Out of order execution Common subexpression elimination or dead code elimination. If the optimizer determines that the 2nd expression has no side effects it might optimize it away. But note that raising CONSTRAINT_ERROR is a side effect. So: if X /= null and x.all = 5 then Do_Something; end if; will most likely become: if x = null then raise CONSTRAINT_ERROR; elif x.all = 5 then Do_Something; end if; Or - for a CPU with hardware null pointer detection - it might become: if x.all = 5 then Do_Something; end if; Ada is a language which highly rely on the existence of an optimizer. Unlike the C style languages - the very first C did not have an optimizer and it still show in the syntax and semantic.- One should always remember C's main design goal: compiler must fit's into 8 kb of memory. It explains a lot. Anyway by default Ada leaves all option options open to the optimizer. For example: type Byte is range -128 .. 127; might not actually be a byte - especially when optimized for performance. By default all options are open to the optimizer to make the best of you wish. Only when you start restricting the optimizer with for Byte'Size use 8; you are guaranteed an 8 bit type. You consider this when thinking of "or else" and "and then" - both restrict the optimizer in it's doing and the result might not be faster. Regards Martin -- mailto://krischik@users.sourceforge.net Ada programming at: http://ada.krischik.com