comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Ada202X: Easy to use "UML private"-like components
Date: Sun, 23 Jun 2013 10:32:12 +0300
Date: 2013-06-23T10:32:12+03:00	[thread overview]
Message-ID: <b2nmjsFrifnU1@mid.individual.net> (raw)
In-Reply-To: <91qcs81k6am9l3u3n19lj0b072lc48td69@4ax.com>

On 13-06-23 06:26 , Dennis Lee Bieber wrote:
> On Sun, 23 Jun 2013 01:57:17 +0300, Niklas Holsti
> <niklas.holsti@tidorum.invalid> declaimed the following:
> 
>>
>> Maybe my post was unclear: I tried to contradict Bob Duff's recollection
>> that an opaque type in Modula-2 is more like an Ada private type than
>> like an "stt access type". I think that a Modula-2 opaque type is very
>> similar to an "stt access type". Do you agree with me?
> 
> 	Having just refetched a few days of the thread to find out what "stt
> access type" means, I can not comment on your assertion.

The term was also unfamiliar to me, before Bob Duff's post. To make it
clear, I think ( :-) ) we are discussing a structure of this form:

   package Pkg is
      type T is private;
      ... operations on T ...
   private
      type Object; -- Will be completed in the body of Pkg.
      type T is access Object;
   end Pkg;

Here Pkg.T is the type used by the clients, and is the "stt access
type", because it is an access to an incompletely declared type,
Pkg.Object. The type Pkg.Object is completed in the package body:

   package body Pkg is
      type Object is ... whatever ...
      ... operation bodies ...
   end Pkg;

Pkg.T corresponds to a Modula-2 opaque type (or opaque eport, if you
prefer). Both the Ada compiler and the Modula-2 compiler know, based on
the package declaration or the definition module, that Pkg.T is a
pointer. Neither compiler knows anything about the type of the object to
which Pkg.T points, until the package body or implementation module is
compiled.

As far as I can see, the main difference between Ada and Modula-2 is
that the Ada package declaration has to name the underlying type
(Pkg.Object), because it has to declare Pkg.T as "access Object". That
is not necessary in the Modula-2 definition module, because the opaque
type declaration in Modula-2 implies that the type is a pointer. (As I
understand it, Modula-2 has no other concept of "private type".)

> 	So whatever these "stt access types" are, they are not something I've
> encountered in my use of Python -- they sound a lot like a programming
> convention for subverting what the compiler was designed to handle.

They provide further separation of the declaration and implementation o
the type, just as the Modula-2 opaque types do, and with the same
drawbacks (see below).

> Modula-2's opaque exports, OTOH, are the compiler's requirement for
> handling data abstraction -- not something a programmer just uses in lieu
> of some other paradigm.

Because Modula-2 has no other way to privatize types.

In Ada, the "private type" feature lets you hide the structure of a type
from clients, yet reveal it fully in the package declaration, for the
compiler's benefit. You can then decide whether or not to use an access
type, i.e. an "stt access type" such as Pkg.T above. If you use an
access type, you can defer the full declaration of the underlying type
(and the necessary "with" clauses) to the package body, but this usually
requires heap allocation of the objects.

I tend to use "stt access types" when the type in question (e.g. Pkg.T)
needs reference semantics and heap allocation anyway. (Being rather
conservative in my programming style, I haven't yet leapt fully into
controlled types.)

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
      .      @       .

  reply	other threads:[~2013-06-23  7:32 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-21  8:43 Ada202X: Easy to use "UML private"-like components Martin
2013-06-21  9:23 ` Dmitry A. Kazakov
2013-06-21  9:33   ` Martin
2013-06-21 10:14     ` G.B.
2013-06-21 11:19       ` Martin
2013-06-21 14:51     ` Dmitry A. Kazakov
2013-06-22 11:16       ` Martin
2013-06-22 12:10         ` Dmitry A. Kazakov
2013-06-21 18:36 ` Robert A Duff
2013-06-22 16:41   ` Niklas Holsti
2013-06-22 19:05     ` Dennis Lee Bieber
2013-06-22 22:57       ` Niklas Holsti
2013-06-23  3:26         ` Dennis Lee Bieber
2013-06-23  7:32           ` Niklas Holsti [this message]
2013-06-23 13:12             ` Robert A Duff
2013-06-23 14:06               ` Dmitry A. Kazakov
2013-06-23 15:15                 ` Robert A Duff
2013-06-23 18:52                   ` Dmitry A. Kazakov
2013-06-23 23:38                     ` Robert A Duff
2013-06-24  7:16                       ` Dmitry A. Kazakov
2013-06-24 20:11                         ` Randy Brukardt
2013-06-25  7:21                           ` Dmitry A. Kazakov
2013-06-25 19:06                             ` Randy Brukardt
2013-06-24 20:07                 ` Randy Brukardt
2013-06-23 14:40               ` Shark8
2013-06-23 15:28                 ` Robert A Duff
2013-06-23 18:14                   ` Bill Findlay
2013-06-23 23:43                     ` Robert A Duff
2013-06-23 23:48                       ` Bill Findlay
2013-06-24 20:16                   ` Randy Brukardt
2013-06-24 20:05               ` Randy Brukardt
2013-06-25  1:09                 ` Robert A Duff
2013-06-25 19:37                   ` Randy Brukardt
2013-06-23 12:28         ` Robert A Duff
2013-06-24 20:20           ` Randy Brukardt
2013-06-24 21:40             ` Niklas Holsti
2013-06-25  0:43               ` Robert A Duff
2013-06-25 19:23                 ` Randy Brukardt
2013-06-25 19:19               ` Randy Brukardt
2013-07-09 11:24   ` Martin
2013-07-09 14:39     ` Simon Wright
2013-07-10  7:03       ` Martin
2013-07-09 21:43     ` Robert A Duff
2013-07-10  6:34       ` Martin
2013-07-10  8:24         ` Dmitry A. Kazakov
2013-07-10 13:06           ` Martin
2013-07-10 16:12     ` Simon Wright
2013-07-10 18:22       ` Martin
2013-07-10 19:41         ` Simon Wright
2013-07-11 18:28           ` Martin
2013-07-11 19:37             ` Simon Wright
2013-07-11 20:43               ` Martin
2013-07-12  6:57                 ` Simon Wright
2013-07-12  8:05                   ` Martin
replies disabled

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