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.2 required=5.0 tests=BAYES_00,INVALID_DATE, PDS_OTHER_BAD_TLD autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uunet!igor!rutabaga!jls From: jls@rutabaga.Rational.COM (Jim Showalter) Newsgroups: comp.lang.ada Subject: Re: Pre-condition vs. Post-condition Keywords: pre-condition, post-condition, exception Message-ID: Date: 19 Mar 91 07:38:59 GMT References: <344@platypus.uofs.edu> <2865@sparko.gwu.edu> <97779@tut.cis.ohio-state.edu> Sender: news@Rational.COM List-Id: >procedure pop(s: stack) >begin > if(not empty(s)) then > -- pop the stack > else > raise underflow >end pop; >procedure pop(s: stack) >begin > stack.top := stack.top - 1; > exception > when Constraint_Error => raise underflow >end pop; Note that in the second case the procedure is faster, since it doesn't have to do the check first. Not only is it faster, it is safer, since without using tasks you cannot guarantee that between the time you checked and the time you popped it hadn't been popped elsewhere. For both of these reasons, I'd say the second version is far better than the first version, and that the original poster's thesis that exceptions should be used rarely if ever has been contradicted by the very examples provided to support his/her case! P.S. You need an "end if" in the first example. -- ***** DISCLAIMER: The opinions expressed herein are my own. Duh. Like you'd ever be able to find a company (or, for that matter, very many people) with opinions like mine. -- "When I want your opinion, I'll read it in your entrails."