comp.lang.ada
 help / color / mirror / Atom feed
From: Richard D Riehle <laoXhai@ix.netcom.com>
Subject: Re: Help me to chose between ADA 95 and C++
Date: 1999/12/20
Date: 1999-12-20T23:49:11+00:00	[thread overview]
Message-ID: <83mf9n$p3b$1@nntp1.atl.mindspring.net> (raw)
In-Reply-To: 385bab78_3@news1.prserv.net

In article <385bab78_3@news1.prserv.net>,
	"Matthew Heaney" <matthew_heaney@acm.org> wrote:


>But you can add and even subtract operations from a scalar type:
>
>  type Counter is new Integer;
>
>  function "+" (L, R : Counter) return Counter is abstract;
>
>  function "-" (L, R : Counter) return Counter is abstract;
>
>You can then use Counter'Succ and Counter'Pred.

I am aware of this fact, Matthew.  The example I posted has the
benefit of 1) enforcing information hiding,  2) a set of
operations with single, unambiguous usage, and 3) considerable
simplicity.  I suppose one could argue about this, but it would
be ultimately a matter of opinion rather than a matter of technical
superiority of one form over the other.

>
>You can also replace operations:
>
>  type Heading_Type_Base delta 1.0/2**(-16) range -720.0 .. 720.0;
>
>  subtype Heading_Type is
>    Heading_Type_Base range 0.0 .. Heading_Type_Base'Pred (360.0);
>
>  function Predefined_Add
>    (L, R : Heading_Type_Base) return Heading_Type_Base renames "+";
>
>  function "+" (L, R : Heading_Type) return Heading_Type;
>
>  function Predefined_Subtract
>    (L, R : Heading_Type_Base) return Heading_Type_Base renames "-";
>
>  function "-" (L, R : Heading_Type) return Heading_Type;
>
>Now you can implement "+" and "-" to have wrap-around behaviour:
>
>  H := 359.0;
>  H := H + 2.0;  -- H = 1.0
>  H := 5.0;
>  H := H - 10.0;  -- H = 355.0
>
Again, this is not new information.  It seems stylistically a little
excessive, but not obscene.  My original point was that, now and then
it is useful to be able to declare a numeric type as private.  Not 
always.  Simply that, it is nice to have that capability available.
>
>But pre- and post-condition checking is a separate issue from overriding
>predefined operators of a scalar type.  We could declare your divide op
>for a non-private type:
>
>  type T is new Float;
>
>  function Predefined_Divide (L, R : T) return T renames "/";
>
>  function "/" (R, L : T) return T;
>
>
>You may prefer to not use an infix operator at all:
>
>  type T is new Float;
>
>  function Div (Dividend, Divisor : T) return T;
>
This does not behave exactly as the example I posted.  Also, if I
plan to export my own division, I don't want to also export the
predefined version.  This would be a case where I would want a
private type to prevent anyone from using the predefined division.
>
>In any case you're free to raise whatever exceptions are appropriate.
>
Only if there is an opportunity to do so before actually using the
predefined operators.  That is exactly the point.
>
>As far as pre- and post-condition checking goes, I prefer to check using
>pragma Assert.  No, this is not an official standard, but it is a de
>facto standard.  (There's even an AI to add this pragma to the
>language.)
>
pragma Assert is a nice addition to some compilers.  As you note, it is
not part of the standard and not implemented in all compilers.  
>
>Agreed, but this doesn't mean you have to declare the type as private.
>
Maybe not, but declaring the type private ensures that I export only
the operators relevant to the abstraction intended.  It is not a matter
of _have to_ , it is a matter of what is appropriate under a particular
set of circumstances.  

Richard Riehle




  reply	other threads:[~1999-12-20  0:00 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-12-15  0:00 Help me to chose between ADA 95 and C++ Robert C. Leif, Ph.D.
1999-12-16  0:00 ` Richard D Riehle
1999-12-16  0:00   ` Matthew Heaney
1999-12-17  0:00     ` Richard D Riehle
1999-12-18  0:00       ` Matthew Heaney
1999-12-20  0:00         ` Richard D Riehle [this message]
  -- strict thread matches above, loose matches on Subject: below --
1999-12-22  0:00 Help me to chose between ADA 95 and C++ ( Ehud Lamm
1999-12-14  0:00 Help me to chose between ADA 95 and C++ Robert C. Leif, Ph.D.
1999-12-15  0:00 ` Richard D Riehle
1999-11-26  0:00 Robert
1999-11-26  0:00 ` Harald Schmidt
1999-11-26  0:00   ` Andreas Winckler
1999-11-26  0:00     ` Florian Weimer
1999-12-04  0:00   ` Richard D Riehle
     [not found]     ` <01bf3e32$0b9dc880$022a6282@dieppe>
1999-12-10  0:00       ` Chris Powell
1999-12-13  0:00         ` Marin D. Condic
1999-12-13  0:00         ` Richard D Riehle
1999-12-14  0:00           ` Chris Powell
1999-12-14  0:00             ` Simon Wright
1999-12-15  0:00               ` Chris Powell
1999-12-15  0:00                 ` Robert A Duff
1999-12-14  0:00             ` Larry Kilgallen
1999-12-15  0:00               ` Robert A Duff
2000-01-12  0:00                 ` Richard Pinkall-Pollei
1999-12-14  0:00             ` Ray Blaak
1999-12-14  0:00             ` Richard D Riehle
1999-12-14  0:00               ` Matthew Heaney
1999-12-15  0:00             ` Ted Dennison
1999-12-20  0:00               ` Stefan Skoglund
1999-12-16  0:00             ` Pascal Obry
1999-12-16  0:00               ` Aidan Skinner
1999-12-16  0:00               ` Lutz Donnerhacke
1999-12-16  0:00               ` Rakesh Malhotra
1999-12-21  0:00                 ` Geoff Bull
1999-12-21  0:00             ` Robert Dewar
1999-12-21  0:00               ` Chris Powell
1999-12-21  0:00               ` Ted Dennison
1999-12-21  0:00                 ` Robert Dewar
1999-12-13  0:00         ` Brian Rogoff
1999-12-14  0:00           ` Chris Powell
1999-12-14  0:00             ` Preben Randhol
1999-12-14  0:00               ` Stephen Leake
1999-12-14  0:00                 ` Tucker Taft
1999-12-15  0:00                   ` Stephen Leake
1999-12-15  0:00                 ` Preben Randhol
1999-12-14  0:00             ` Brian Rogoff
1999-12-15  0:00           ` Richard Pinkall-Pollei
1999-12-15  0:00             ` Richard Pinkall-Pollei
1999-12-21  0:00             ` Geoff Bull
1999-12-21  0:00               ` Tucker Taft
1999-12-22  0:00                 ` Ted Dennison
1999-12-13  0:00         ` DuckE
1999-12-14  0:00           ` Matthew Heaney
1999-12-14  0:00         ` Matthew Heaney
1999-12-14  0:00           ` Chris Powell
1999-12-14  0:00             ` Tucker Taft
1999-12-14  0:00               ` Matthew Heaney
1999-12-23  0:00               ` Chris Powell
1999-12-27  0:00                 ` Robert A Duff
1999-12-14  0:00             ` Matthew Heaney
1999-12-15  0:00               ` Hyman Rosen
1999-12-14  0:00             ` Stephen Leake
1999-12-23  0:00               ` Chris Powell
1999-11-26  0:00 ` Andreas Winckler
1999-11-26  0:00 ` Preben Randhol
1999-11-26  0:00   ` Preben Randhol
1999-11-27  0:00 ` Lionel Draghi
replies disabled

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