comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Smart pointers and delegation
Date: Wed, 9 Aug 2017 17:57:11 -0500
Date: 2017-08-09T17:57:11-05:00	[thread overview]
Message-ID: <omg407$2an$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: omee2p$145a$1@gioia.aioe.org

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
news:omee2p$145a$1@gioia.aioe.org...
> On 2017-08-09 02:27, Randy Brukardt wrote:
>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
>> news:omblk3$svi$1@gioia.aioe.org...
>
>>> Why would I want this, if the reference manages the object? The cardinal
>>> difference is between object-managed references and reference-managed
>>> objects. The former has a very limited use and would prefer to have all 
>>> of
>>> them built-in.
>>
>> In that case, you definitely need to know precisely when the reference 
>> dies,
>> so you can "manage the object".
>
> Right. That is the advantage of the approach. Reference's life-time is 
> better defined than the object's one. E.g. references can be scoped when 
> the object cannot. Or, more importantly, when the object must stay hidden 
> or is inaccessible like system resource or remote objects.
>
>> If you have a lifetime leak (such as any
>> normal access type does), then you can't do that management safely.
>
> It happens when references are components of other objects and/or have 
> circular dependencies. Therefore strong and weak references go.
>
>> The pattern of the intended use-case of Implicit_Dereference does exactly 
>> this.
>
> It cannot replace smart pointer, because it does not manage the object. So 
> the question is whether implicit dereference can be a part of smart 
> pointer:
>
>    target <-- smart pointer with implicit dereference
>
> This does not work for multiple reasons either.

I find this surprising. It works in the use-cases I've tried. (I haven't 
tried a pure Smart-Pointer, although others have, since I prefer to include 
such things in a larger abstract - like a container).

...
> So the solution could only be ugly heavy-weighted:
>
>    target <-- smart pointer
>       ||           |
>       ||           | operation to produce helper object
>       ||           V
>    target <-- helper object with implicit dereference
>
> This has no advantages whatsoever. Ergo, implicit dereference has no use 
> for smart pointers.

Even if true, the "real problem" however remains. If you can safely and 
efficiently copy the designated object, then you have no need for 
Implicit_Dereference. If you need "return-by-reference", though, you need 
some special mechanism to do that. We tried a variety of approaches, and 
none of them worked out that well (there are 4 alternatives for 
AI05-0142-1). Thus we ended up with Implicit_Dereference.

Perhaps in a brand-new language, it would be possible to make a sensible 
definition of return-by-reference directly, but it doesn't make sense in Ada 
given the existing model and requirements.

                                        Randy.


  reply	other threads:[~2017-08-09 22:57 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-01 10:32 Smart pointers and delegation Dmitry A. Kazakov
2017-08-01 15:06 ` Dmitry A. Kazakov
2017-08-01 23:06 ` Randy Brukardt
2017-08-02  6:20   ` Dmitry A. Kazakov
2017-08-03  3:36     ` Randy Brukardt
2017-08-03  7:40       ` Dmitry A. Kazakov
2017-08-04 23:03         ` Randy Brukardt
2017-08-05  8:33           ` Dmitry A. Kazakov
2017-08-07 22:39             ` Randy Brukardt
2017-08-08  6:27               ` Dmitry A. Kazakov
2017-08-09  0:27                 ` Randy Brukardt
2017-08-09  7:37                   ` Dmitry A. Kazakov
2017-08-09 22:57                     ` Randy Brukardt [this message]
2017-08-10  7:56                       ` Dmitry A. Kazakov
2017-08-11  0:17                         ` Randy Brukardt
2017-08-11  6:43                           ` Dmitry A. Kazakov
2017-08-11 20:37                             ` 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