On Thursday, 23 May 2013 at 20:19:28 UTC, Nick Sabalausky wrote:
On Thu, 23 May 2013 23:09:54 +1000
Manu <[email protected]> wrote:

On 23 May 2013 22:56, Max Samukha <[email protected]> wrote:
>
> You have module constructors in mixins. How did you solve the
> circular imports problem? Banned circular imports?
>

Pretty much.
I anticipate the problem arising, but it hasn't come up.
The codebase is fairly hierarchical it seems...

I'd really rather not do it with module constructors though. There might be other solutions, like module locals executing constructors
or something.


I don't know whether there might be a problem with this approach in your particular situation, but I always try to avoid module ctors by
using lazy-inited module-level properties:

// From:
Foo foo;
static this {
    foo = ...etc...;
}

---->

// To:
private Foo _foo;
private bool fooInited;
@property Foo foo() {

    if(!fooInited) {
        foo = ...etc...;
        fooInited = true;
    }

    return _foo;
}


A little more boiler-platey, but that be cleaned up with mixins. And then if I need to force init to happen right at start-up, then I can
just make sure to "touch" each of the properties at startup.

Problems start when the state needs to be thread-shared.

Reply via email to