comp.lang.ada
 help / color / mirror / Atom feed
From: Keean Schupke <keean.schupke@googlemail.com>
Subject: Re: Signature Package With Generic Proceedure
Date: Mon, 23 Jul 2012 11:29:01 -0700 (PDT)
Date: 2012-07-23T11:29:01-07:00	[thread overview]
Message-ID: <b75aa4da-5c73-4fae-9f0e-68078f7378b9@googlegroups.com> (raw)
In-Reply-To: <500d3a9d$0$6566$9b4e6d93@newsspool4.arcor-online.net>

On Monday, 23 July 2012 12:50:52 UTC+1, Georg Bauhaus  wrote:
> On 23.07.12 09:30, Keean Schupke wrote:
> &gt; Object oriented techniques all have considerable runtime costs due to using tagged types, and virtual functions (no inlining).
> 
> Nitpick: O-O in Ada would not necessarily preclude inlining,
> since, by default, finding the primitive subprogram is
> dynamic IFF there is dispatching (when &#39;Class is involved).
> 
> GNAT inlines OO.a and OO.b in clients of the following package
> when the object of type T is specific:
> 
> package OO is
>   type T is tagged record
>     x : Natural;
>   end record;
> 
>   function a (Object : T) return Natural;
>   function b (Object : T; off : Natural) return Natural;
>   pragma inline (a, b);
> end OO;
> 
> package body OO is
>   function a (Object : T) return Natural is (Object.x);
>   function b (Object : T; off : Natural) return Natural is
>   begin
>      return natural&#39;max (1000, Object.x + off);
>   end;
> end OO;

In the example you give surely the record does not need to be tagged at all, in which case this is really just functions and types, no OO at all (and would have been possible in Ada83?). Get rid of the tag, and then parameterise on the type of the object using generics... you can now reuse the same code with different types of Objects.

There is more to it than my bad descriptions. Look at type-classes in Haskell, google "datatype generic programming", and read Stepanov's "Elements of Programming".

Cheers,
Keean.



  parent reply	other threads:[~2012-07-26 15:20 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <045f7b44-2a4a-4292-80fd-0b6bc8ee3465@googlegroups.com>
2012-07-21 22:22 ` Signature Package With Generic Proceedure Adam Beneschan
2012-07-22  7:28   ` Dmitry A. Kazakov
2012-07-22 16:22   ` Keean Schupke
2012-07-23  0:45     ` Adam Beneschan
     [not found]       ` <79925d0c-b2dd-44a3-9451-48f0ee19485f@googlegroups.com>
     [not found]         ` <500d3a9d$0$6566$9b4e6d93@newsspool4.arcor-online.net>
2012-07-23 18:29           ` Keean Schupke [this message]
     [not found]         ` <ac8bfaed-dbcc-491a-a760-c25672445eef@googlegroups.com>
2012-07-23 19:41           ` Keean Schupke
2012-07-24  2:57         ` Randy Brukardt
     [not found]         ` <jul2n4$af5$1@munin.nbi.dk>
2012-07-24  8:02           ` Keean Schupke
2012-07-24  8:43             ` Dmitry A. Kazakov
2012-07-24  8:59               ` Keean Schupke
2012-07-23 10:26 ` Simon Wright
2012-07-23 18:36   ` Keean Schupke
replies disabled

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