Groups | Search | Server Info | Login | Register
Groups > comp.lang.ada > #59637
| From | Nioclás Pól Caileán de Ghloucester <thanks-to@Taf.com> |
|---|---|
| Newsgroups | comp.lang.ada |
| Subject | Re: GNAT messages and the not operator (pitfall alert!) |
| Date | 2026-01-07 13:01 +0100 |
| Organization | To protect and to server |
| Message-ID | <3df03142-538d-6a60-e867-d71249aff4cc@insomnia247.nl> (permalink) |
| References | <dewar.846163972@merv> <54snn6$8j5@newsbf02.news.aol.com> |
John J Herro wrote in 1996: #--------------------------------------------------------------------------# #"dewar@merv.cs.nyu.edu (Robert Dewar) writes: # #> Ask an Ada expert what is the value of # #> -5 mod 3 # #> Almost anyone [gets it wrong] ... the default # #> parenthesiztion of this expression is -(5 mod 3). # # # #This brings us to a coding style rule that I wish everyone would follow. # #Use parentheses unless the order of evaluaton is VERY OBVIOUS. A person # #reading your code should _never_ have to go to the RM to look up the # #precedence of operators, and certainly you should never refer to that # #section when writing code; use parentheses instead. # # # #I'm not saying that the code # # # # if X**2 + 3.0*X + 2.0 < 100.0 then ... # # # #should be cluttered with unnecessary parentheses. Everyone knows that # #"**" comes before "*" and "/", which come before binary "+" and "-", and # #everyone knows that the relational operators have a low precedence. It's # #also arguable that "everyone" knows that "and" comes before "or". But I'd# #say in almost every other case, unless the order of evaluation is very # #obvious, use parentheses! # # # #Even Ada has some pitfalls. If everyone followed this rule, one of them # #would be no problem. # # # #- John Herro # #Software Innovations Technology # #http://members.aol.com/AdaTutor # #ftp://members.aol.com/AdaTutor" # #--------------------------------------------------------------------------# Matthew Heaney wrote in 1996: |---------------------------------------------------------------------------| |"In article <54snn6$8j5@newsbf02.news.aol.com>, johnherro@aol.com (John | |Herro) wrote: | | | |>It's also arguable that "everyone" knows that "and" comes before "or". | | | |Are you sure? My understanding is that "and" and "or" have equal | |precedence, and that Ada *requires* the use of parens to force to | |programmer to state his intent. | | | |The Ada 83 explains that because we've all been taught algebraic logic | |since we were young whipper-snappers, the precedence of "+" and "*" is | |well-kwown. But because we haven't all been taught relational logic that | |long, there's some potential ambiguity. So Ada eliminates it once and for | |all by forcing the use parens. | | | |The thing I'd like to add, however, is to admonish programmers to not to | |write complicated predicates! If you're writing a predicate that requires | |the use of "a lot of" parens, then try to re-think your solution. As has | |been noted in this group before, one of the largest sources of errors | |(perhaps _the_ largest) is predicates, especially getting loop termination | |correct. | | | |Please, please, if you need to leave a loop early, then use "exit when..." | |or return. I've often seen code (even in software engineering texts that | |use Ada examples) that sets a loop flag to false, that in turn gets tested | |at the top of the (while) loop. This is clearly a misuse of the language | |and a violation of all the principles of programming as a _human_ activity,| |as you've just doubled the number of states you have to test! | | | |-------------------------------------------------------------------- | |Matthew Heaney | |Software Development Consultant | |mheaney@ni.net | |(818) 985-1271" | |---------------------------------------------------------------------------| Use parentheses! A publication by the Association of C & C++ Users reveals that survey answerers at a conference of the Association of C & C++ Users have not known that multiplication or dvision takes precedence over binary addition or subtraction! Old persons can forget things which they had been taught when they used to be young whipper-snappers.
Back to comp.lang.ada | Previous | Next — Next in thread | Find similar
Re: GNAT messages and the not operator (pitfall alert!) Nioclás Pól Caileán de Ghloucester <thanks-to@Taf.com> - 2026-01-07 13:01 +0100
Re: GNAT messages and the not operator (pitfall alert!) Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-01-07 20:27 +0000
Re: GNAT messages and the not operator (pitfall alert!) Kevin Chadwick <kc-usenet@chadwicks.me.uk> - 2026-01-10 10:07 +0000
Re: GNAT messages and the not operator (pitfall alert!) Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-01-10 21:01 +0000
Re: GNAT messages and the not operator (pitfall alert!) dirk@orka.cs.kuleuven.be. (Dirk Craeynest) - 2026-01-11 18:29 +0000
Re: GNAT messages and the not operator (pitfall alert!) Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-01-11 20:21 +0000
Re: GNAT messages and the not operator (pitfall alert!) dirk@orka.cs.kuleuven.be. (Dirk Craeynest) - 2026-01-12 09:55 +0000
Re: GNAT messages and the not operator (pitfall alert!) Bill Findlay <findlaybill@blueyonder.co.uk> - 2026-01-12 16:13 +0000
Re: GNAT messages and the not operator (pitfall alert!) Nioclás Pól Caileán de Ghloucester <thanks-to@Taf.com> - 2026-02-13 12:22 +0000
Re: GNAT messages and the not operator (pitfall alert!) Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-02-13 21:46 +0000
Re: GNAT messages and the not operator (pitfall alert!) Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-02-13 13:57 -0800
csiph-web