comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: best practice: error handling
Date: Sat, 11 Jun 2011 16:07:34 +0200
Date: 2011-06-11T16:07:34+02:00	[thread overview]
Message-ID: <1835s5a847r9q$.191jzvxwbypk8.dlg@40tude.net> (raw)
In-Reply-To: op.vwwzpxqvule2fv@douda-yannick

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  
> <mailbox@dmitry-kazakov.de> 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



  reply	other threads:[~2011-06-11 14:07 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-31 14:01 best practice: error handling milouz
2011-05-31 17:13 ` Vinzent Hoefler
2011-05-31 17:57   ` AdaMagica
2011-06-11 13:38   ` Yannick Duchêne (Hibou57)
2011-05-31 18:08 ` Jeffrey Carter
2011-05-31 20:02   ` Dmitry A. Kazakov
2011-05-31 20:35     ` Jeffrey Carter
2011-05-31 21:40       ` Dmitry A. Kazakov
2011-06-11 13:57     ` Yannick Duchêne (Hibou57)
2011-06-11 14:07       ` Dmitry A. Kazakov [this message]
2011-06-12  5:19         ` Randy Brukardt
2011-06-11 13:48   ` Yannick Duchêne (Hibou57)
2011-06-11 13:31 ` Yannick Duchêne (Hibou57)
2011-06-11 16:12   ` Simon Wright
2011-06-11 16:26   ` Dmitry A. Kazakov
replies disabled

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