comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@ni.net (Matthew Heaney)
Subject: Re: GNAT messages and the not operator (pitfall alert!)
Date: 1996/10/26
Date: 1996-10-26T00:00:00+00:00	[thread overview]
Message-ID: <mheaney-ya023180002610962159410001@news.ni.net> (raw)
In-Reply-To: 54snn6$8j5@newsbf02.news.aol.com


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




  parent reply	other threads:[~1996-10-26  0:00 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-10-24  0:00 GNAT messages and the not operator (pitfall alert!) Robert Dewar
1996-10-24  0:00 ` Robert Dewar
1996-10-25  0:00   ` whiting_ms@corning.com (Matt Whiting)
1996-10-26  0:00     ` David C. Hoos, Sr.
1996-10-27  0:00     ` Robert Dewar
1996-10-28  0:00       ` Matthew S. Whiting
1996-10-26  0:00   ` John Herro
1996-10-26  0:00     ` Robert Dewar
1996-10-29  0:00       ` John Herro
1996-10-29  0:00         ` Robert Dewar
1996-10-26  0:00     ` Matthew Heaney [this message]
1996-10-29  0:00       ` Robert Dewar
1996-10-30  0:00     ` Dr. Peter E. Obermayer
1996-10-30  0:00       ` John Herro
1996-10-30  0:00         ` Robert Dewar
1996-11-01  0:00         ` User Password expiration date extractor? Stein-Aksel Basma
1996-10-29  0:00   ` GNAT messages and the not operator (pitfall alert!) Norman H. Cohen
1996-10-29  0:00     ` whiting_ms@corning.com (Matt Whiting)
1996-10-30  0:00       ` David C. Hoos, Sr.
1996-10-30  0:00         ` whiting_ms@corning.com (Matt Whiting)
1996-10-30  0:00           ` Norman H. Cohen
1996-10-30  0:00       ` Norman H. Cohen
1996-11-06  0:00         ` Richard A. O'Keefe
1996-11-18  0:00           ` Norman H. Cohen
1996-11-18  0:00             ` Robert Dewar
1996-10-30  0:00       ` Robert Dewar
1996-11-05  0:00     ` Robert Dewar
1996-10-28  0:00 ` Cary Jamison
1996-10-29  0:00   ` Robert Dewar
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox