comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: User-defined type attributes (replacing genericity)
Date: Fri, 14 Mar 2008 19:58:18 +0100
Date: 2008-03-14T19:58:19+01:00	[thread overview]
Message-ID: <199nmfx3bkxkf$.1sllgktbwkbur.dlg@40tude.net> (raw)
In-Reply-To: 821256cd-2d20-46dd-92d2-cdd21181dbb8@s8g2000prg.googlegroups.com

On Fri, 14 Mar 2008 10:51:25 -0700 (PDT), Eric Hughes wrote:

> On Fri, 14 Mar 2008 15:31:40 +0100, Georg Bauhaus wrote:
>> Without generics, there is only one Is_Highest, as might be
>> expected.
> 
> On Mar 14, 8:48 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
>> Why there have to be two? The whole idea of generics was to have *one*
>> generic body. This is why it is called generic [programming].
> 
> Here's the nut of the problem.  There is one generic body in the code
> of the programming language.  When you substitute type parameters into
> that generic body, you get multiple different manifestations of that
> original generic body, that is, multiple bodies, one for each type.
> And that means multiple versions as translated into machine code.

No, Ada is not like that. In fact much efforts, at least in Ada 83, was
paid in order to allow sharing of generic bodies. AFAIK, Janus Ada shares
them.

> This is indeed the primary desideratum of generic programming.  Having
> said this, there's a standard technique of converting type operations
> into virtual function calls.  I feel like I need to say this--these
> aren't the same thing.  This allows the reduction of the manifestation
> a generic body to a single canonical form.  This has a single version
> in machine code.

It is optimization technique. You could instruct the compiler to inline a
class-wide body. You could require to generate a separate instance for each
used combination of argument types. Semantically the body is still same.

> A realistic system for generic programming should support both modes
> of code generation.  This allows the developer to determine their own
> answer to the code-size vs. performance trade-off.  Ada has already
> taken the stance, as evidenced by representation clauses, that it will
> support both high and low levels of abstraction.

If that were true it would be a premature optimization. Anyway semantically
there is no any difference between generic and class-wide bodies. Both act
on a class of types.

To be honest, there are formal generic parameters beyond types:

1. Formal objects. These are not required and covered by plain functions.
Normally they are used to work around language limitations, usually in
types algebra, which is the weak point.

2. Formal packages. This looks like a useful thing, but child packages and
better classes might make them superfluous.

> Eliminating generics
> would force everything into virtual function calls, choose code-size
> over performance, and make that choice on behalf of every programmer.
> If you go down the road of requiring all method calls to be virtual,

Note that class-wide bodies do not dispatch.

> of requiring that there be run-time manifestations of all meta-
> language features, you get Java.  Java has its place.  So does Ada.
> These aren't the same place.

Similarly I could argue that Ada generics (at least as you an George
describe them) is a preprocessor. There are many. Right, they are poorly
designed, untyped etc. But who said that Java was designed properly?

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



  reply	other threads:[~2008-03-14 18:58 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-12 18:58 User-defined type attributes Eric Hughes
2008-03-12 21:23 ` Dmitry A. Kazakov
2008-03-13 18:32   ` Eric Hughes
2008-03-13 19:58     ` Dmitry A. Kazakov
2008-03-14  1:46       ` Randy Brukardt
2008-03-14  1:46       ` Randy Brukardt
2008-03-14  1:46       ` Randy Brukardt
2008-03-14  9:00         ` Dmitry A. Kazakov
2008-03-14 14:36           ` User-defined type attributes (replacing genericity) Georg Bauhaus
2008-03-15  3:04           ` User-defined type attributes Randy Brukardt
2008-03-15  9:33             ` Dmitry A. Kazakov
2008-03-14 14:31         ` User-defined type attributes (replacing genericity) Georg Bauhaus
2008-03-14 14:48           ` Dmitry A. Kazakov
2008-03-14 17:51             ` Eric Hughes
2008-03-14 18:58               ` Dmitry A. Kazakov [this message]
2008-03-14 20:19                 ` Eric Hughes
2008-03-15  4:01               ` Randy Brukardt
2008-03-14 16:58           ` Georg Bauhaus
2008-03-14 18:39             ` Dmitry A. Kazakov
2008-03-15  9:39               ` Dmitry A. Kazakov
2008-03-14  3:55       ` User-defined type attributes Eric Hughes
2008-03-14  9:01         ` Dmitry A. Kazakov
2008-03-14 18:04           ` Eric Hughes
2008-03-14  1:46 ` Randy Brukardt
2008-03-14  4:41   ` Eric Hughes
2008-03-15  3:20     ` Randy Brukardt
2008-03-17  4:38       ` Eric Hughes
2008-03-17 21:03         ` Randy Brukardt
2008-03-17 21:58           ` Eric Hughes
replies disabled

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