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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ec21c3c7cdc7ff3e X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!wns14feed!worldnet.att.net!attbi_s22.POSTED!53ab2750!not-for-mail From: "Jeffrey R. Carter" Organization: jrcarter at acm dot org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060130 SeaMonkey/1.0 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Handling invalid objects References: <1142279908.327131.230200@j52g2000cwj.googlegroups.com> <41LSf.4126$TK2.1805@trnddc07> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 12.214.35.215 X-Complaints-To: abuse@mchsi.com X-Trace: attbi_s22 1142889447 12.214.35.215 (Mon, 20 Mar 2006 21:17:27 GMT) NNTP-Posting-Date: Mon, 20 Mar 2006 21:17:27 GMT Date: Mon, 20 Mar 2006 21:17:27 GMT Xref: g2news1.google.com comp.lang.ada:3504 Date: 2006-03-20T21:17:27+00:00 List-Id: Brian May wrote: > > item &find_item(...) { > > ... search for item ... > > if (found) { > return item; > } else { > return ????; > } > } > > The ideal solution would be exceptions, but the students haven't been > taught exceptions yet when conducting this exercise. No, exceptions are not ideal. Such a function may often be used in contexts where not finding a match is more common than finding one; the former case is not exceptional. Consider a program like grep. It applies a regular-expression-matching function to every line in a file. It's quite common for > 80% of the matches to fail; that is not an exceptional situation. Using an exception to indicate no match would be incorrect. Booch made this fundamental error in the regular expression matcher in his components book. > Another solution would be to change the API to return a struct value, > but students are told they cannot change the API. Then what the student has is an incorrect specification that cannot be implemented. -- Jeff Carter "From this day on, the official language of San Marcos will be Swedish." Bananas 28