[Dlang-study] [lifetime] Few root decisions to take on RC classes
Martin Nowak
code at dawg.eu
Mon Nov 2 07:38:50 PST 2015
On 11/02/2015 01:20 AM, Andrei Alexandrescu wrote:
> class Widget
> static Widget g;
> void fun()
> {
> g = this;
> }
> }
>
> If we make the entire Widget reference-counted, the compiler knows how
> to make the code work. If we go the @noescape route, this code and
> others like it will be statically disallowed. So we end up with
> something more restrictive (or more complicated if we decide to allow
> certain escape patterns).
Why are we trying so hard to make bad code work? Sharing the ownership
of a class from within a method can be very surprising and can always be
replaced by sharing with the function (passing as argument)/assigning on
the callsite.
Even more important the @rc scheme doesn't seem to solve a much more
common use case.
class Widget
{
void fun()
{
escapingReferenceToFoo(field);
}
Foo field;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/dlang-study/attachments/20151102/7c3a5aa7/attachment.sig>
More information about the Dlang-study
mailing list