• Re: GNAT messages and the not operator (pitfall alert!)

    From =?UTF-8?Q?Niocl=C3=A1s_P=C3=B3l_Caile=C3=A1n_de_Ghloucester?=@[email protected] to comp.lang.ada on Wed Jan 7 13:01:53 2026
    From Newsgroup: comp.lang.ada

    John J Herro wrote in 1996: #--------------------------------------------------------------------------# #"[email protected] (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$[email protected]>, [email protected] (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 | |[email protected] | |(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.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@[email protected] to comp.lang.ada on Wed Jan 7 20:27:12 2026
    From Newsgroup: comp.lang.ada

    On Wed, 7 Jan 2026 13:01:53 +0100, Nioclás Pól Caileán de Ghloucester
    wrote:

    John J Herro wrote in 1996:

    #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 wonder why we bother to have operator precedence rules, then? Give
    all operators the same precedence, and make the grouping parentheses
    mandatory.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Kevin Chadwick@[email protected] to comp.lang.ada on Sat Jan 10 10:07:26 2026
    From Newsgroup: comp.lang.ada

    #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 wonder why we bother to have operator precedence rules, then? Give
    all operators the same precedence, and make the grouping parentheses >mandatory.

    +1

    After bugs this is now a Linux kernel rule. Took Linux longer than it should
    to specify best practice though.
    --
    Regards, Kc
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@[email protected] to comp.lang.ada on Sat Jan 10 21:01:09 2026
    From Newsgroup: comp.lang.ada

    On Sat, 10 Jan 2026 10:07:26 -0000 (UTC), Kevin Chadwick wrote:

    On Wed, 7 Jan 2026 20:27:12 -0000 (UTC), Lawrence D’Oliveiro wrote:

    On Wed, 7 Jan 2026 13:01:53 +0100, Nioclás Pól Caileán de
    Ghloucester wrote:

    John J Herro wrote in 1996:


    #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 wonder why we bother to have operator precedence rules, then?
    Give all operators the same precedence, and make the grouping
    parentheses mandatory.

    +1

    In which case, why bother with infix operators at all? Why not
    construct all your expressions out of function calls, à la Lisp?

    So instead of

    2 + (3 × 5)

    or

    (2 + 3) × 5

    you could have

    (+ 2 (× 3 5))

    or

    (× (+ 2 3) 5)

    respectively. Bye-bye precedence issues!
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From dirk@[email protected]. (Dirk Craeynest) to comp.lang.ada on Sun Jan 11 18:29:13 2026
    From Newsgroup: comp.lang.ada

    In article <10juemk$3eijl$[email protected]>,
    Lawrence D�Oliveiro <[email protected]d> wrote:
    So instead of
    2 + (3 × 5)
    or
    (2 + 3) × 5

    you could have
    (+ 2 (× 3 5))
    or
    (× (+ 2 3) 5)

    respectively. Bye-bye precedence issues!

    Brings back fond memories of the HP calculators with RPN (Reverse Polish Notation)...

    https://www.hpmuseum.org/rpn.htm
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@[email protected] to comp.lang.ada on Sun Jan 11 20:21:20 2026
    From Newsgroup: comp.lang.ada

    On Sun, 11 Jan 2026 18:29:13 -0000 (UTC), Dirk Craeynest wrote:

    On Wed, 7 Jan 2026 20:27:12 -0000 (UTC), Lawrence D’Oliveiro wrote:

    So instead of

    2 + (3 × 5)

    or

    (2 + 3) × 5

    you could have

    (+ 2 (× 3 5))

    or

    (× (+ 2 3) 5)

    respectively. Bye-bye precedence issues!

    Brings back fond memories of the HP calculators with RPN ...

    What I posted is “PN” -- “RPN” without the “R”.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From dirk@[email protected]. (Dirk Craeynest) to comp.lang.ada on Mon Jan 12 09:55:59 2026
    From Newsgroup: comp.lang.ada

    On Sun, 11 Jan 2026 18:29:13 -0000 (UTC), Dirk Craeynest wrote:
    Brings back fond memories of the HP calculators with RPN ...

    Lawrence D'Oliveiro <[email protected]d> wrote:
    What I posted is 'PN' -- 'RPN' without the 'R'.

    Sure. Nevertheless, your post brought back those memories... ;-)
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Bill Findlay@[email protected] to comp.lang.ada on Mon Jan 12 16:13:43 2026
    From Newsgroup: comp.lang.ada

    On 11 Jan 2026, Dirk Craeynest wrote
    (in article <10k0q5p$3oia$[email protected]>):

    Brings back fond memories of the HP calculators with RPN (Reverse Polish Notation)...

    A computer that used an RPN instruction set was the English Electric KDF9.

    You can see snippets of KDF9 assembler here: <http://www.findlayw.plus.com/KDF9/#PSK>

    That code was generated by a 21st century KDF9 Pascal cross-compiler
    called paskal, and can be executed by a KDF9 emulator called ee9.

    Both paskal and ee9 are written in ... Ada 2012.

    You can find them here: <http://www.findlayw.plus.com/KDF9/emulation/emulator.html#Download>
    --
    Bill Findlay


    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From thanks-to@[email protected] to comp.lang.ada on Fri Feb 13 12:22:03 2026
    From Newsgroup: comp.lang.ada

    Lawrence D’Oliveiro <[email protected]d> wrote:
    |----------------------------|
    |"Bye-bye precedence issues!"|
    |----------------------------|

    "Developer beliefs about binary operator precedence
    Knowledge Software, Ltd
    Farnborough, Hants, England
    Derek M. Jones
    [. . .]
    While coding guideline often contain a recommendation specifying that
    operator precedence be made explicit
    through the use of parenthesis, experience shows that developers are
    often loath to insert what they consider
    to be redundant parenthesis (because “Everybody knows what the
    precedence is and if they don’t they should
    not be working on this code”). Subject operator pair performance
    should be all the evidence needed to
    convince people that redundant parenthesis do provide a useful
    service."
    says
    HTTP://WWW.Knosof.co.UK/dev-experiment/accu06a.pdf

    (S. HTTP://Gloucester.Insomnia247.NL/ fuer Kontaktdaten!)
    --- Synchronet 3.21b-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@[email protected] to comp.lang.ada on Fri Feb 13 21:46:01 2026
    From Newsgroup: comp.lang.ada

    On Fri, 13 Feb 2026 12:22:03 -0000 (UTC), Nioclás Pól Caileán de
    Ghloucester wrote:

    ... experience shows that developers are often loath to insert what
    they consider to be redundant parenthesis (because “Everybody knows
    what the precedence is ...

    Or because, you know, if in doubt they can refer to the documentation,
    which they always keep handy, right?
    --- Synchronet 3.21b-Linux NewsLink 1.2
  • From Keith Thompson@[email protected] to comp.lang.ada on Fri Feb 13 13:57:00 2026
    From Newsgroup: comp.lang.ada

    Lawrence D’Oliveiro <[email protected]d> writes:
    On Fri, 13 Feb 2026 12:22:03 -0000 (UTC), Nioclás Pól Caileán de Ghloucester wrote:

    ... experience shows that developers are often loath to insert what
    they consider to be redundant parenthesis (because “Everybody knows
    what the precedence is ...

    Or because, you know, if in doubt they can refer to the documentation,
    which they always keep handy, right?

    Certainly, but consulting the documentation can increase the time it
    takes to read an expression by an order of magnitude or more.
    --
    Keith Thompson (The_Other_Keith) [email protected]
    void Void(void) { Void(); } /* The recursive call of the void */
    --- Synchronet 3.21b-Linux NewsLink 1.2