comp.lang.ada
 help / color / mirror / Atom feed
From: Shark8 <onewingedshark@gmail.com>
Subject: Re: Generics vs. O-O?
Date: Fri, 2 Aug 2013 08:08:38 -0700 (PDT)
Date: 2013-08-02T08:08:38-07:00	[thread overview]
Message-ID: <8bef1dc4-547b-478e-b81a-09077212f821@googlegroups.com> (raw)
In-Reply-To: <1so729qnkrrj2.ztrxvmlw6cb7.dlg@40tude.net>

On Friday, August 2, 2013 8:09:46 AM UTC-6, Dmitry A. Kazakov wrote:
> 
> 
> > For example, if
> > you'd want a callback to be passed somewhere. Then, dismissing generics
> > might entail the introduction of one level of indirection (subprogram
> > pointer),
> 
> There is no need in using pointers in order to achieve downward closures.
> It was a kludge of Ada 95 design. Generics is a kludge of Ada 83 design.

No, it was a well thought-out and justified feature; see the Ada83 rationale:

12.1 Introduction
Generic units are a general form of parameterized program units. As with other parameterization mechanisms, the primary purpose is factorization, resulting in a reduction in the size of the program text while also improving maintainability, readability, and efficiency.

Parameterization by generic units is a natural extension of subprogram parameterization. When otherwise identical actions differ by a particular value or variable, these actions may be encapsulated in a subprogram where the value or variable appears as a parameter. Having thereby factored out the common part, the text becomes smaller and easier to read; and clerical errors, resulting from accidental lack of identity among the copies, are eliminated. Moreover, compilers can take advantage of this commonality to produce more compact code.

Traditional parameterization mechanisms are usually in terms of values and variables. But the same factorization arguments apply when two otherwise identical program units differ by some other property, such as a type. 

> Yet another language design
> problem that there is no simple way to declare such singleton types in Ada.

Really?
In Ada 2012 I can say the following:

    package Test is

	Type K is Private;
	
	J : Integer := 12;
	
    private
	use type System.address;
	
	type K is new integer with TYPE_INVARIANT => K'Address = J'Address;
    end test;

Type K sure looks like a singleton to me.


  reply	other threads:[~2013-08-02 15:08 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-01 14:45 Generics vs. O-O? Eryndlia Mavourneen
2013-08-01 19:24 ` Dmitry A. Kazakov
2013-08-01 19:52   ` Eryndlia Mavourneen
2013-08-01 20:14     ` sbelmont700
2013-08-01 23:35       ` Yannick Duchêne (Hibou57)
2013-08-01 20:10   ` optikos
2013-08-01 20:26     ` Dmitry A. Kazakov
2013-08-01 20:35     ` Jeffrey Carter
2013-08-01 21:22     ` Bill Findlay
2013-08-01 23:38     ` Yannick Duchêne (Hibou57)
2013-08-01 22:20   ` Georg Bauhaus
2013-08-02  8:11     ` Dmitry A. Kazakov
2013-08-02  9:50       ` Georg Bauhaus
2013-08-02 14:09         ` Dmitry A. Kazakov
2013-08-02 15:08           ` Shark8 [this message]
2013-08-02 15:36             ` Alan Jump
2013-08-02 17:00               ` Jeffrey Carter
2013-08-02 17:51               ` Dmitry A. Kazakov
2013-08-02 18:06                 ` Alan Jump
2013-08-02 19:08                   ` Dmitry A. Kazakov
2013-08-02 16:15             ` Dmitry A. Kazakov
2013-08-03  0:04       ` Yannick Duchêne (Hibou57)
2013-08-03  7:35         ` Georg Bauhaus
2013-08-03  8:57           ` Dmitry A. Kazakov
replies disabled

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