comp.lang.ada
 help / color / mirror / Atom feed
From: Joachim Durchholz <joachim.durchholz@munich.netsurf.de>
Subject: Re: Building blocks (Was: Design By Contract)
Date: 1997/10/16
Date: 1997-10-16T00:00:00+00:00	[thread overview]
Message-ID: <3445AB56.BF10D04@munich.netsurf.de> (raw)
In-Reply-To: 5w3FnzA6KRR0Iwt+@treetop.demon.co.uk


Paul Johnson wrote:
> 
> I agree that the repeated read (or whatever instruction) before the
> loop and at the end is a bad idea.  Quite apart from the Soloway
> experiment, it is duplicating code.

Me too (on both accounts).

> OTOH I wonder if the situation might be reversed in real life
> situations with deeply nested structures.  I'm rather dubious of
> small, neat coding experiments such as Soloway's.

I can support that from personal experience. Whenever code involved
'break'ing out from several nesting levels deep, it was rather
unreadable and difficult to decipher.

However, there's a middle ground between "break only at top of loop" and
"break everywhere within a loop": "break anywhere at the top level
within a loop". A syntax for this might look like this:

  loop
    ...
  until <condition>
    ...
  until <condition>
    ...
  end loop

so one could write

  loop
    <read a value>
  until value = '0'
    <process value>
  end loop

This avoids both the obfuscation from breaking out from deeply nested
code *and* the code duplication necessary if the termination condition
is forced to the top of the loop.

To satisfy those who are concerned with making sure that the loop does
what it has to, and terminates (hi Eiffelists!), the syntax could be set
up as follows:

<loop> ::=
  from
    <loop set-up statements - syntactic sugar>
  loop
    <loop statement>
    <loop statement>
    ...
  end

<loop statement> ::=
  [invariant <condition>] -- must be true on every iteration
  [variant <expression>]  -- must decrease on every iteration
                          -- must not decrease beyond a given threshold
                          -- (this ensures that the loop terminates)
  until <expression>      -- termination condition

<loop statement> ::=
  <statement>             -- normal statements are allowed, too :)

i.e. within the loop body, an arbitrary number of
  invariant ...
  variant ...
  until ...
sequences can be placed, with invariant and variant optional. The
postcondition of the loop would be the OR of all the invariants ANDed
with their respective "until" conditions, so having too many loop exits
will make checking and understanding the loop more work, so the number
of loop exits should be small. Actually I'm not sure wether such a
syntax shouldn't be limited to a single exit - I have very rarely felt
the need for mutliple loop exits, and a bit of inconvenience in rare
cases is always worth a better language structure.

Regards,
Joachim
-- 
Please don't send unsolicited ads. (The @@ is for confusing spambots.)






  parent reply	other threads:[~1997-10-16  0:00 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-09-09  0:00 Building blocks (Was: Design By Contract) Marc Wachowitz
1997-09-15  0:00 ` Joachim Durchholz
1997-09-17  0:00 ` Paul Johnson
1997-09-18  0:00   ` Robert Dewar
1997-09-18  0:00   ` Jon S Anthony
1997-09-18  0:00   ` Stephen Leake
1997-09-18  0:00     ` Mark L. Fussell
     [not found]       ` <11861963wnr@eiffel.demon.co.uk>
1997-09-19  0:00         ` Mark L. Fussell
1997-09-19  0:00       ` Robert A Duff
1997-09-20  0:00         ` Joachim Durchholz
1997-09-22  0:00           ` Matthew Heaney
1997-09-23  0:00             ` Joachim Durchholz
1997-09-23  0:00             ` Veli-Pekka Nousiainen
1997-10-03  0:00               ` Robert I. Eachus
1997-10-04  0:00                 ` Paul Johnson
1997-10-14  0:00                   ` Robert I. Eachus
1997-09-23  0:00           ` Jon S Anthony
1997-09-24  0:00           ` Alan E & Carmel J Brain
1997-09-25  0:00             ` Anonymous
1997-09-30  0:00               ` Alan E & Carmel J Brain
1997-09-30  0:00                 ` Matthew Heaney
1997-09-30  0:00                   ` W. Wesley Groleau x4923
1997-09-30  0:00                     ` Matthew Heaney
1997-10-01  0:00                     ` Alan E & Carmel J Brain
1997-09-30  0:00                   ` Neil Wilson
1997-09-30  0:00                     ` Stephen Leake
1997-10-01  0:00                 ` Anonymous
1997-10-01  0:00                   ` Paul M Gover
1997-10-04  0:00                     ` Paul Johnson
1997-10-04  0:00                       ` Matthew Heaney
1997-10-15  0:00                         ` Paul Johnson
1997-10-15  0:00                           ` Matthew Heaney
1997-10-16  0:00                             ` Joachim Durchholz
1997-10-17  0:00                               ` Robert I. Eachus
1997-10-16  0:00                           ` Joachim Durchholz [this message]
1997-10-22  0:00                           ` Reimer Behrends
1997-10-01  0:00                   ` Joachim Durchholz
1997-10-02  0:00                   ` Robert A Duff
1997-10-02  0:00                     ` Tucker Taft
1997-10-02  0:00                       ` Matthew Heaney
1997-10-03  0:00                     ` Stephen Leake
1997-10-04  0:00                     ` Matthew Heaney
1997-10-07  0:00                       ` Robert A Duff
1997-09-24  0:00           ` Richard A. O'Keefe
1997-09-19  0:00       ` Jon S Anthony
1997-09-23  0:00         ` Mark L. Fussell
1997-09-18  0:00     ` W. Wesley Groleau x4923
1997-09-21  0:00       ` Matthew Heaney
  -- strict thread matches above, loose matches on Subject: below --
1997-09-11  0:00 Robert Dewar
1997-09-09  0:00 Marc Wachowitz
1997-09-02  0:00 Design By Contract Jon S Anthony
     [not found] ` <JSA.97Sep3201329@alexandria.organon.com>
1997-09-04  0:00   ` Paul Johnson
     [not found]     ` <5un58u$9ih$1@gonzo.sun3.iaf.nl>
1997-09-06  0:00       ` Building blocks (Was: Design By Contract) Joachim Durchholz
1997-09-08  0:00       ` Paul Johnson
1997-09-08  0:00         ` Brian Rogoff
1997-09-09  0:00           ` W. Wesley Groleau x4923
1997-09-09  0:00           ` Matthew Heaney
1997-09-09  0:00             ` W. Wesley Groleau x4923
1997-09-10  0:00               ` Robert A Duff
1997-09-12  0:00                 ` Jon S Anthony
1997-09-09  0:00             ` Brian Rogoff
1997-09-10  0:00             ` Paul Johnson
1997-09-10  0:00               ` Matthew Heaney
1997-09-10  0:00               ` Darren New
1997-09-10  0:00             ` Robert Dewar
1997-09-12  0:00               ` Paul Johnson
1997-09-14  0:00                 ` Robert Dewar
1997-09-14  0:00                 ` Robert Dewar
1997-09-15  0:00                   ` John G. Volan
1997-09-14  0:00                 ` Robert Dewar
1997-09-12  0:00               ` Jon S Anthony
1997-09-12  0:00                 ` Robert Dewar
1997-09-16  0:00                   ` Brian Rogoff
1997-09-09  0:00           ` Veli-Pekka Nousiainen
1997-09-09  0:00           ` Veli-Pekka Nousiainen
1997-09-09  0:00             ` Jon S Anthony
replies disabled

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