DConf 2013 Day 1 Talk 5: Using D Alongside a Game Engine by Manu Evans

Max Samukha maxsamukha at gmail.com
Fri May 24 05:54:03 PDT 2013


On Thursday, 23 May 2013 at 20:19:28 UTC, Nick Sabalausky wrote:
> On Thu, 23 May 2013 23:09:54 +1000
> Manu <turkeyman at gmail.com> wrote:
>
>> On 23 May 2013 22:56, Max Samukha <maxsamukha at gmail.com> 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.


More information about the Digitalmars-d-announce mailing list