comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Should weak counted reference be able to be strengthened?
Date: Tue, 25 Nov 2014 09:36:37 +0100
Date: 2014-11-25T09:36:37+01:00	[thread overview]
Message-ID: <1xbl1kdcf9at5.1dfv4py4kvx0o.dlg@40tude.net> (raw)
In-Reply-To: m50alf$mpm$1@loke.gir.dk

On Mon, 24 Nov 2014 16:15:10 -0600, Randy Brukardt wrote:

> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
> news:1tlppwq452jbq$.d1y3trfego8b$.dlg@40tude.net...
>> On Fri, 21 Nov 2014 16:39:25 -0600, Randy Brukardt wrote:
>>
> ...
>> [...]
>>> The real question is whether there is a real need to have a long-lived
>>> Strong_Reference. I would argue against such a thing, but I don't think 
>>> it is clearly an open-and-shut case.
>>
>> Sure, the only purpose of strong references is to be long-lived.
> 
> But you (almost?) never need such a thing, at least not without access to 
> underlying object as well. Thus I suggested unifying the Accessor and the 
> Strong_Reference.

Right. But I go one step further and hide target type altogether making
only the reference visible.

Actually, reference like an access type must inherit the target object's
interface. The original Ada 83 design was right with regard to indexing and
record member operations inherited by access types. It should have
inherited everything including assignment.

Access type assignment should have a different notation unless ":=" were
specifically overridden. Especially because copying pointers is always
dangerous.

>>> Sure, but now you have an extra function with no real purpose. If you use
>>> the accessor form, you don't need any way at all to get the pointer, you
>>> always have access to it.
>>
>> Accessor is a whole type without purpose and all functions it has are
>> without purpose as well.
> 
> I was suggesting that "Accessor" actually be named "Strong_Reference"; I can 
> see no need for a separate Strong_Reference type. As such, there's no extra 
> type here. Instead, you have an extra function "Ptr" which serves no purpose 
> except an extra complication. :-)

Ptr was needed to keep it Ada 95 compatible.

An Ada 2005 design would hide the target object type altogether.

   type T_Interface is interface ...
   procedure Foo (X : T_Interface) is abstract;

privately:

   type T is ... and T_Interface ...  -- Object implementation
   overriding procedure Foo (X : T);

publicly

  type T_Reference is ... and T_Interface with private;
   overriding procedure Foo (X : T_Reference);
private
  type T_Ptr is access T;
  type T_Reference is ... and T_Interface with record
      Ptr : T_Ptr;
  end record;

  procedure Foo (X : T_Reference) is
  begin
     X.Ptr.Foo; -- Delegation
  end Foo;

Instead of introducing "crazy beautiful" implicit dereference, Ada 2012
should have delegation support for the patterns like this.

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

  reply	other threads:[~2014-11-25  8:36 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-21 11:07 Should weak counted reference be able to be strengthened? Natasha Kerensikova
2014-11-21 13:16 ` Dmitry A. Kazakov
2014-11-21 15:00   ` Natasha Kerensikova
2014-11-21 16:50     ` Dmitry A. Kazakov
2014-11-21 18:24       ` Natasha Kerensikova
2014-11-21 19:36         ` Dmitry A. Kazakov
2014-11-21 22:28           ` Randy Brukardt
2014-11-22  9:57           ` Natasha Kerensikova
2014-11-22 10:19             ` Dmitry A. Kazakov
2014-11-22 10:36               ` Natasha Kerensikova
2014-11-22 11:15                 ` Dmitry A. Kazakov
2014-11-21 22:39       ` Randy Brukardt
2014-11-21 22:49         ` Shark8
2014-11-22  8:42           ` Dmitry A. Kazakov
2014-11-22  8:42         ` Dmitry A. Kazakov
2014-11-24 22:15           ` Randy Brukardt
2014-11-25  8:36             ` Dmitry A. Kazakov [this message]
2014-11-25 21:49               ` Randy Brukardt
2014-11-26  9:28                 ` Dmitry A. Kazakov
2014-11-26 17:51                   ` brbarkstrom
2014-11-26 21:09                   ` Randy Brukardt
replies disabled

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