[Dlang-study] [lifetime] Few root decisions to take on RC classes

Martin Nowak code at dawg.eu
Fri Nov 6 09:48:18 PST 2015


On 11/02/2015 05:07 PM, Andrei Alexandrescu wrote:
> Well so I'm unclear then. You asserted that code escaping a class
> reference is in poor style and we needn't support it. But now you're
> asserting code that escapes the address of an int is a "much more common
> case". These two can't be simultaneously true.

It's better to do `globalCallbackList.add(klass)` then
`klass.addYourselfToGlobalCallbackList()`. The code is more loosely
coupled and the owner of the class is the one escaping the reference.

And because of that it's more common to escape a field of a class than
it is to escape the whole class in a method.

> * Structs and primitive data types are not supposed to escape freely in
> safe code so we can afford to restrict escaping for them.

Really? There is nothing preventing me from this atm.

struct Ref
{
    int* p;
    int[] ary;
}

class Foo
{
    auto foo() @safe
    {
        return new Ref(&field, ary[]);
    }

    int field;
    int[4] ary;
}

-------------- 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/20151106/5b85c2b9/attachment.sig>


More information about the Dlang-study mailing list