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!news2.google.com!newshub.sdsu.edu!newsfeed.straub-nv.de!news.motzarella.org!motzarella.org!not-for-mail From: Keith Thompson Newsgroups: comp.lang.ada Subject: Re: and then... (a curiosity) Date: Tue, 02 Sep 2008 10:00:16 -0700 Organization: None to speak of Message-ID: References: <18b41828-bda4-4484-8884-ad62ce1c831d@f36g2000hsa.googlegroups.com> <57qdnfULQ9tzKCHVnZ2dnUVZ_tHinZ2d@comcast.com> <48bd0003$1@news.post.ch> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: feeder.motzarella.org U2FsdGVkX1+pBqRZktx9Uvuncs3ULa2po+6HlkPmU/MbCr+YusjUYrVpSMCMerYFQrfXpP6xyD0taU6hgHOLkU2D/txjDkBd2wcH1GL3TCOv/GZEfXgl8190SjPf3hd46P3K7dLJqUk= X-Complaints-To: Please send complaints to abuse@motzarella.org with full headers NNTP-Posting-Date: Tue, 2 Sep 2008 17:00:19 +0000 (UTC) X-Auth-Sender: U2FsdGVkX19+WTPIZGP+2t8WQYY3L8DU Cancel-Lock: sha1:GVjDPRmz+1KFjGvQa7KZmzBaebs= sha1:JTqo+/1CRBlMH0+lu0P4rf3jWsU= User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (gnu/linux) Xref: g2news1.google.com comp.lang.ada:1873 Date: 2008-09-02T10:00:16-07:00 List-Id: stefan-lucks@see-the.signature writes: [...] > Well, if the program requirements are that the side effects for A and B > actually occur, I consider it poor programming style if people just write > > if A(X) and B(Y) then ... end if; > > IMHO, much better style is the following: > > declare > Tmp_A: Boolean := A(X); > Tmp_B: Boolean := B(X); > begin > if Tmp_A and Tmp_B then ... end if; > end; > > This makes the programmers intention clear, "if A(X) and B(X)" doesn't. [...] (As you said in a later followup, you meant B(Y) rather than B(X).) I disagree. The shorter form if A(X) and B(Y) then ... end if; makes the programmer's intent absolutely clear to anyone who knows what "and" means in Ada. If I saw the other version my first thought would be to wonder why the programmer didn't just write "if A(X) and B(Y)". After a moment's thought, I'd assume that the order of evaluation of A(X) and B(Y) is significant. It would never occur to me that the long form was used to ensure that both A(X) and B(Y) are evaluated, since the "and" operator already does that. All programming languages have their quirks, and none of them exactly follow mathematical notation (in part because there is no single mathematical notation). If you try to write code that will be understandable to someone who doesn't know the language, you'll end up with an overly verbose mess that can hardly be understood by someone who *does* know the language. If I were doing the equivalent of the above in C, whose logical "and" operator "&&" does do short-circuit evaluation, I probably would declare the two temporaries. In Ada, it's just not necessary. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"