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,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fac41,f66d11aeda114c52 X-Google-Attributes: gidfac41,public X-Google-Thread: 103376,f66d11aeda114c52 X-Google-Attributes: gid103376,public From: nobody@REPLAY.COM (Anonymous) Subject: Re: Building blocks (Was: Design By Contract) Date: 1997/09/25 Message-ID: <199709251320.PAA03585@basement.replay.com>#1/1 X-Deja-AN: 275468617 References: <342A0AC6.2F2F@dynamite.com.au> X-001: Replay may or may not approve of the content of this posting X-002: Report misuse of this automated service to X-URL: http://www.replay.com/remailer/ Organization: Replay and Company UnLimited Mail-To-News-Contact: postmaster@nym.alias.net Newsgroups: comp.lang.ada,comp.lang.eiffel Date: 1997-09-25T00:00:00+00:00 List-Id: <5v34m5$pl9$1@trumpet.uni-mannheim.de> <34215E3D.77AE@gsfc.nasa.gov> <3421E190.49CC@chimu.com> <3423BE13.9C3852A4@munich.netsurf.de> On Wed, 24 Sep 1997 23:55:02 -0700, Alan E & Carmel J Brain wrote: >[...] > If you want to resume, or retry, or whatever, you need to confine the > exception to it's own block. A typical example looks something like: > > (Declarations, Constants omitted for simplicity) > > UnTransmitted := true; > ReTryCounter := 0; > > while UnTransmitted loop > > if ReTryCounter > MaxRetries then > raise LineContinuouslyBusy; end if; -- Line Too busy > -- Report this upwards > Transmission_Attempt_Block : > begin > > Ethernet.TryToTransmit; > UnTransmitted := false; -- Successful Transmission > > exception > when Ethernet.LINE_BUSY => > ReTryCounter := ReTryCounter+1; -- Try again > -- Note that this 'handles' > -- the exception > when Ethernet.NACK => > Untransmitted := false; -- Ignore Negative Ack. > -- Again, exception handled. > when others => raise; > -- something unexpected and Nasty, Propagate it out! > > end Transmission_Attempt_Block; > > end loop; > This doesn't seem typical to me. It differs from typical in 1. Using mixed-case identifiers instead of underline-separated identifiers (ReTryCounter instead of Re_Try_Counter). 2. Using while instead of loop/exit (ref. Ichbiah, Barnes, & Firth, "Ada Launch," 1980 Dec 10, videotape, on why while was included in the language). 3. The design of Ethernet is faulty, since it uses exceptions for non-exceptional circumstances (line busy, NACK received). 4. Unusual formatting of the if. If we have to use Ethernet as is, I'd say the following is more typical Retry_Counter := 0; Send : loop if Retry_Counter > Max_Retries then raise Line_Continuously_Busy; end if; -- Line too busy; report this upwards Try_One : begin Ethernet.Try_To_Transmit; exit Send; -- Successful transmission exception -- Try_One when Ethernet.Line_Busy => Retry_Counter := Retry_Counter + 1; -- Try again when Ethernet.Nack => exit Send; -- Accept NACK as success end Try_One; end loop Send; Jeff Carter PGP:1024/440FBE21 My real e-mail address: ( carter @ innocon . com ) "You brightly-colored, mealy-templed, cranberry-smelling, electric donkey-bottom biters." Monty Python & the Holy Grail Posted with Spam Hater - see http://www.compulink.co.uk/~net-services/spam/