comp.lang.ada
 help / color / mirror / Atom feed
From: Marius Amado Alves <amado.alves@netcabo.pt>
To: comp.lang.ada@ada-france.org
Subject: Re: Why can't you create a out of order subtype?
Date: Wed, 2 Feb 2005 20:22:58 +0000
Date: 2005-02-02T20:22:58+00:00	[thread overview]
Message-ID: <mailman.115.1107375662.527.comp.lang.ada@ada-france.org> (raw)
In-Reply-To: <uwttqaj9l.fsf@obry.org>

>> declare
>>     M : Msg := Whatever;
>>     V : Vowelmsg;
>> begin
>>     V := Vowelmsg'Value (Msg'Image (M));
>>     -- if control reaches here then M is a vowel
>> exception
>>     when Constraint_Error => -- M is not a vowel
>> end;
>
> I don't think this is good style. The above code use exception for non
> exceptional case. It uses exception as a if statement. Definitely 
> something
> to avoid.

No, not definitely. As you say it's a matter of style. This has come up 
before many times. It's the issue of using exceptions for logic in 
certain situations. There are two well established schools of thought 
on this. One says "no", the other says "yes". Obviously you belong to 
the former, and I to the latter. There are other respectful people of 
both schools other than you and I. At the "exceptional" workshop of 
Ada-Europe 2001 in Leuven this was very noticeable. Other situations 
where we the "yeses" find the use of exceptions for logic adequate 
include end of file detection. Also note that the idiom above is very 
similar to invalid data detection, where the use of exceptions is 
deemed adequate even in your school. Also note that the alternative 
idiom using Unchecked_Conversion hurts sensibilities in yet another 
school where the use of UC in this situation would be frowned upon. 
Also note that M failing to be a vowel can be considered exceptional = 
abnormal, a somewhat fuzzy notion. In sum, I neither agree or disagreed 
with you. To my eyes the exception idiom is acceptable here for all the 
stated reasons and more. But I accept the contrary view. Because there 
are fuzzy notions involved. My advice to the original poster is: just 
pick the idiom you 'feel' comfortable with, and carry on. Enrolment is 
gratis in either school :-)




  reply	other threads:[~2005-02-02 20:22 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-01 23:51 Why can't you create a out of order subtype? brett_gengler
2005-02-02  0:24 ` Jeffrey Carter
2005-02-02 17:55   ` Marius Amado Alves
2005-02-02 18:50     ` Pascal Obry
2005-02-02 20:22       ` Marius Amado Alves [this message]
2005-02-03  4:36       ` Wes Groleau
2005-02-03 12:59         ` Marius Amado Alves
2005-02-04  3:42           ` Wes Groleau
2005-02-02 19:35     ` Martin Dowie
2005-02-02 20:35       ` Marius Amado Alves
2005-02-02 21:18         ` Martin Dowie
2005-02-03 19:40       ` Robert A Duff
2005-02-03 20:22         ` Marius Amado Alves
2005-02-03 22:05           ` Robert A Duff
2005-02-04  6:49           ` Martin Dowie
2005-02-02 22:26 ` Georg Bauhaus
2005-02-03 23:09 ` Robert A Duff
replies disabled

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