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.3 required=5.0 tests=BAYES_00,FREEMAIL_FROM, INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3b4bed4f74b8ac49 X-Google-Attributes: gid103376,public From: johnherro@aol.com (John Herro) Subject: Re: GNAT messages and the not operator (pitfall alert!) Date: 1996/10/26 Message-ID: <54snn6$8j5@newsbf02.news.aol.com>#1/1 X-Deja-AN: 192187911 sender: root@newsbf02.news.aol.com references: organization: America Online, Inc. (1-800-827-6364) newsgroups: comp.lang.ada Date: 1996-10-26T00:00:00+00:00 List-Id: 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