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: 103376,88858d66e427dbcb,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-11-05 15:28:10 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: svaa@ciberpiula.net (svaa) Newsgroups: comp.lang.ada Subject: Short circuit boolean evaluation Date: 5 Nov 2003 15:28:10 -0800 Organization: http://groups.google.com Message-ID: <87f5a614.0311051528.30450c7a@posting.google.com> NNTP-Posting-Host: 62.82.83.53 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1068074890 22862 127.0.0.1 (5 Nov 2003 23:28:10 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 5 Nov 2003 23:28:10 +0000 (UTC) Xref: archiver1.google.com comp.lang.ada:2112 Date: 2003-11-05T15:28:10-08:00 List-Id: Hello I'm a newbie in Ada, I've worked in several languages, last three years I've worked in Delphi (Pascal). Shouldn't be a good idea to implement short circuit evaluation for boolean expresions as default in Ada0x? Currently Ada uses "and then" and "or else" to implement short circuit. I think it's a burden. The default behavior of "and" and "or" should be "and then" and "or else". The questions are: When is useful short circuit evaluation? when is useful full evaluation? Short circuit evaluation: sometimes it saves you of spliting "if sentence" for previous checks: if (a/=0) and (b/a>k) ... (A quite common event when you chek null pointers). sometimes allows you to decide the order according with you human knowledge of probability of each expression. full evaluation: Let the compiler freedom to optimize the order? In fact, I usually have a clear idea of the order I want the evaluation. Perhaps there are a few cases of simple expresions where I don't mind the order, and I can't guess, at first sight, which has better performance. Probably I can optimize a boolean expresion better than a compiler. I know what's the program about!!. Standard pascal has full evaluation, but most compilers have an option for short circuit evaluation, and it's the default one, that should give a clue. In years of programming I'have never missed the full evaluation, but in some languages that don't use short circuit, I've missed it. As in aritmetic expresions, I'm aware of left to right boolean evaluations, I take advantage of it, and I say ****!!, whenever I have to write "then" after "and" and "else" after "or". Programs will have the same result if you change the behavior to short circuit, but you will save a lot of "then" and "else". Well, I'm missing the case of expresions that call functions. If that function have side efects, you have to evaluate it. I think this is a bad coding style, but perhaps it's because I usually work with short-circuit. In this cases you would lose backward compatibility. Although it could be solved with a pragma. Anyhow, I think that even without backward compatibility, the advanges of short circuit evaluation are worth. But if someone can't live with of full evaluation you could add the operators "or always" and "and always", I'm sure they will be less used than "or else" and "and then" ;-)