comp.lang.ada
 help / color / mirror / Atom feed
* Style Question: normal record vs discriminated null-record.
@ 2014-06-03  2:44 Shark8
  2014-06-03  4:38 ` J-P. Rosen
  2014-06-03  7:19 ` Dmitry A. Kazakov
  0 siblings, 2 replies; 5+ messages in thread
From: Shark8 @ 2014-06-03  2:44 UTC (permalink / raw)


Ok, given some sort of alert-system (meaning there shouldn't be any/much 
in the way of value manipulation of those objects) is it preferable to 
use a discriminated null-record or a record with normal components?


     Type Grievousness is (Warning, Error);
     Type Circumstance is (Expired_Data, Bad_Request, Malformed_Data);

     Type Alert_1(Severity : Grievousness; Condition :  Circumstance) is
     null record;

     Type Alert_2 is record
         Severity  : Grievousness;
         Condition : Circumstance;
     end record;


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Style Question: normal record vs discriminated null-record.
  2014-06-03  2:44 Style Question: normal record vs discriminated null-record Shark8
@ 2014-06-03  4:38 ` J-P. Rosen
  2014-06-03  4:40   ` J-P. Rosen
  2014-06-03  6:20   ` Shark8
  2014-06-03  7:19 ` Dmitry A. Kazakov
  1 sibling, 2 replies; 5+ messages in thread
From: J-P. Rosen @ 2014-06-03  4:38 UTC (permalink / raw)


Le 03/06/2014 04:44, Shark8 a écrit :
> Ok, given some sort of alert-system (meaning there shouldn't be any/much
> in the way of value manipulation of those objects) is it preferable to
> use a discriminated null-record or a record with normal components?
> 
> 
>     Type Grievousness is (Warning, Error);
>     Type Circumstance is (Expired_Data, Bad_Request, Malformed_Data);
> 
>     Type Alert_1(Severity : Grievousness; Condition :  Circumstance) is
>     null record;
> 
>     Type Alert_2 is record
>         Severity  : Grievousness;
>         Condition : Circumstance;
>     end record;
Depends how you perceive your data. Discriminants are intended to define
some kind of subclasses of your type, and can be used to parameterized
inner components. Some criteria for you to chose:

- You can define subtypes according to certain values of discriminants.

- Discriminants are always initialized.

- Discriminants cannot be changed after the declaration.

-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Style Question: normal record vs discriminated null-record.
  2014-06-03  4:38 ` J-P. Rosen
@ 2014-06-03  4:40   ` J-P. Rosen
  2014-06-03  6:20   ` Shark8
  1 sibling, 0 replies; 5+ messages in thread
From: J-P. Rosen @ 2014-06-03  4:40 UTC (permalink / raw)


Le 03/06/2014 06:38, J-P. Rosen a écrit :
> Depends how you perceive your data. Discriminants are intended to define
> some kind of subclasses of your type, and can be used to parameterized
> inner components. Some criteria for you to chose:
> 
> - You can define subtypes according to certain values of discriminants.
> 
> - Discriminants are always initialized.
> 
> - Discriminants cannot be changed after the declaration.
> 
And I forgot:

- You can have a private type whose discriminants are visible (and
components private)

-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Style Question: normal record vs discriminated null-record.
  2014-06-03  4:38 ` J-P. Rosen
  2014-06-03  4:40   ` J-P. Rosen
@ 2014-06-03  6:20   ` Shark8
  1 sibling, 0 replies; 5+ messages in thread
From: Shark8 @ 2014-06-03  6:20 UTC (permalink / raw)


On 02-Jun-14 22:38, J-P. Rosen wrote:
> Depends how you perceive your data. Discriminants are intended to define
> some kind of subclasses of your type, and can be used to parameterized
> inner components. Some criteria for you to chose:
>
> 1 - You can define subtypes according to certain values of discriminants.
>
> 2 - Discriminants are always initialized.
>
> 3 - Discriminants cannot be changed after the declaration.

Right -- the particular situation [alerts] seems like a good fit because 
of these qualities:
(1) Subtypes for critical failures can be defines and quick/clear 
disambiguation/determination in handling [an unconstrained type] via 'in'.
(2) Which means, ideally that the point that generates the alert always 
generates correctly.
(3) That they cannot be altered means that to 'change' the message is to 
handle it and generate a new one -- kind of like "renaming"/re-raising 
exceptions.

This is what makes it seem like a good fit, but I was still wondering 
what "normal Ada programmers" thought about it.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Style Question: normal record vs discriminated null-record.
  2014-06-03  2:44 Style Question: normal record vs discriminated null-record Shark8
  2014-06-03  4:38 ` J-P. Rosen
@ 2014-06-03  7:19 ` Dmitry A. Kazakov
  1 sibling, 0 replies; 5+ messages in thread
From: Dmitry A. Kazakov @ 2014-06-03  7:19 UTC (permalink / raw)


On Mon, 02 Jun 2014 20:44:24 -0600, Shark8 wrote:

> Ok, given some sort of alert-system (meaning there shouldn't be any/much 
> in the way of value manipulation of those objects) is it preferable to 
> use a discriminated null-record or a record with normal components?
> 
>      Type Grievousness is (Warning, Error);
>      Type Circumstance is (Expired_Data, Bad_Request, Malformed_Data);
> 
>      Type Alert_1(Severity : Grievousness; Condition :  Circumstance) is
>      null record;
> 
>      Type Alert_2 is record
>          Severity  : Grievousness;
>          Condition : Circumstance;
>      end record;

My rule of thumb - discriminants whenever possible, components as a
fallback.

I wished Ada allowed discriminants of any type.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-06-03  7:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-03  2:44 Style Question: normal record vs discriminated null-record Shark8
2014-06-03  4:38 ` J-P. Rosen
2014-06-03  4:40   ` J-P. Rosen
2014-06-03  6:20   ` Shark8
2014-06-03  7:19 ` Dmitry A. Kazakov

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