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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c4bd2a19251049b1 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,UTF8 Path: g2news2.google.com!news3.google.com!feeder.news-service.com!94.75.214.39.MISMATCH!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: best practice: error handling Date: Sat, 11 Jun 2011 16:07:34 +0200 Organization: cbb software GmbH Message-ID: <1835s5a847r9q$.191jzvxwbypk8.dlg@40tude.net> References: <0b95a2a1-6e3d-4ad1-a832-e3099a9bce37@v8g2000yqb.googlegroups.com> <1ulcworf418ai$.iy0mm08iuusy.dlg@40tude.net> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: FbOMkhMtVLVmu7IwBnt1tw.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: g2news2.google.com comp.lang.ada:20724 Date: 2011-06-11T16:07:34+02:00 List-Id: On Sat, 11 Jun 2011 15:57:23 +0200, Yannick Duchêne (Hibou57) wrote: > Le Tue, 31 May 2011 22:02:42 +0200, Dmitry A. Kazakov > a écrit: >> Again, the point is valid, but the example is not good. Zero index is as >> good as Index_Result. In both cases an attempt to use the index will >> cause an exception. So both return an "invalid index." > Disagree: an index is an index, not an error status; otherwise this is a > kind of special-value as special-meaning (a special meaning which outside > of the normal type semantic area). You are arguing against special value for an exception. Both Zero index and Index_Result constrained to Found = False are special values. > My experience says its dangerous, > because it is always hard to read that either -1 or 0 or who know what, > was intended to mean Error. Chance are that many people will read 0 as > meaning “Index 0”. No, the value should be invalid for indexing and sustain other operations. Compare it with IEEE's NaN. Zero index could have such property if we redefined index arithmetic so that x + 0 = 0. It is possible to do distinguishing index and offset types in arithmetic (compare with Time and Duration), but to much headache to bother. Index_Result is simpler and works out of the box. BTW, I prefer exceptions to any kind of special values. But as Jeff Carter said, there can be gray zones where special values meaning "not so exceptional" can be used. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de