comp.lang.ada
 help / color / mirror / Atom feed
From: Dmitry A. Kazakov <mailbox@dmitry-kazakov.de>
Subject: Re: The "()" operator revisited.
Date: Thu, 15 Jan 2004 14:23:18 +0100
Date: 2004-01-15T14:23:18+01:00	[thread overview]
Message-ID: <ma3d009bno5ifl362tsetjtv5m6g4dvnma@4ax.com> (raw)
In-Reply-To: bu5sd7$t2u$1@a1-hrz.uni-duisburg.de

On Thu, 15 Jan 2004 11:09:27 +0000 (UTC), Georg Bauhaus
<sb463ba@l1-hrz.uni-duisburg.de> wrote:

>Dmitry A. Kazakov <mailbox@dmitry-kazakov.de> wrote:
>: On Thu, 15 Jan 2004 01:21:16 +0000 (UTC), Georg Bauhaus
>:>Hm. How do you know then that you get an Apple from some Set, and
>:>not an Orange? Is there a run time penalty?
>: 
>: Which one? Templates do it at compile time anyway, so the type tags
>: are statically known.
>
>That is, if I have, in a unit
>procedure generic_array_shuffle(box: Fruit_Array);

No, a "generic" shuffle should be:

procedure generic_array_shuffle(box: Fruit_Array'Class);

>and then in another unit
>declare
>   A: Apple_Array;
>begin generic_array_shuffle(A); end;
>
>declare
>   O: Orange_Array;
>begin generic_array_shuffle(O); end;
>
>the compiler would not be informed about component sizes when
>compiling the unit containing generic_array_shuffle, right?
>Will it then have to, uhm, instantiate a procedure for the two
>calls above with component sizes adjusted, behind the scenes?

Maybe. In your example generic_array_shuffle might be inherited or
overridden. In which case the compiler could take an advantage of
knowing the constraint. Then, the procedure could be inlined, so again
the compiler could re-instantiate its body. Presently optimizations of
this kind are not required. I would define some of them in RM to make
them mandatory.

Futher, if neither applied, what would be a penalty as compared with a
variant based on a generic procedure, which instances are reusing the
body? Actually in the static case, either the constraints have to
propagate into the body, making its reuse impossible, or not. Whether
the body itself is a template or a class-wide is of little matter.

BTW, as Knuth said: "We should forget about small efficiencies, say
about 97% of the time: premature optimization is the root of all
evil." What is the real weight of possible penalties of this kind in a
software project of a real size and application field? I have no
figures, but I suppose it is vanishingly small.

--
Regards,
Dmitry A. Kazakov
www.dmitry-kazakov.de



  reply	other threads:[~2004-01-15 13:23 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-13 17:53 The "()" operator revisited amado.alves
2004-01-14  9:09 ` Dmitry A. Kazakov
2004-01-14 12:55   ` Georg Bauhaus
2004-01-14 15:05     ` Dmitry A. Kazakov
2004-01-15  1:21       ` Georg Bauhaus
2004-01-15  8:50         ` Dmitry A. Kazakov
2004-01-15 11:09           ` Georg Bauhaus
2004-01-15 13:23             ` Dmitry A. Kazakov [this message]
2004-01-17  6:26               ` Robert I. Eachus
2004-01-14 13:04   ` Hyman Rosen
  -- strict thread matches above, loose matches on Subject: below --
2004-01-14 15:22 amado.alves
2004-01-14 16:16 ` Dmitry A. Kazakov
2004-01-13 17:46 amado.alves
2004-01-13 22:21 ` Randy Brukardt
2004-01-12 17:53 Frank J. Lhota
2004-01-12 18:38 ` Frank J. Lhota
2004-01-12 22:26 ` Robert A Duff
2004-01-13 16:29   ` Frank J. Lhota
2004-01-13  9:24 ` Dmitry A. Kazakov
2004-01-13 16:44   ` Frank J. Lhota
2004-01-13 17:13     ` Hyman Rosen
2004-01-13 22:27     ` Randy Brukardt
2004-01-14  2:30     ` Stephen Leake
2004-01-14  9:04     ` Dmitry A. Kazakov
2004-01-17  0:15       ` Kenneth Almquist
2004-01-17 21:15         ` Robert A Duff
2004-01-19 10:25         ` Dmitry A. Kazakov
2004-01-13 13:13 ` Marin David Condic
2004-01-13 17:38   ` Warren W. Gay VE3WWG
2004-01-13 19:09     ` Robert A Duff
2004-01-15 17:30       ` Warren W. Gay VE3WWG
2004-01-15 18:11         ` Robert A Duff
2004-01-15 19:36           ` tmoran
2004-01-15 20:35             ` Robert A Duff
2004-01-17  5:48               ` Robert I. Eachus
2004-01-16  3:11           ` Mark A. Biggar
2004-01-16 13:28             ` Hyman Rosen
2004-01-16 16:19             ` Robert A Duff
2004-01-16 18:09             ` Warren W. Gay VE3WWG
2004-01-16 13:56           ` Frank J. Lhota
2004-01-16 16:14             ` Robert A Duff
2004-01-16 21:29               ` Frank J. Lhota
replies disabled

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