any tool to at least partially convert C++ to D (htod for source
grauzone
none at example.net
Wed Mar 10 15:14:57 PST 2010
Ellery Newcomer wrote:
> I hate the restriction on modules with static constructors and cyclic
> dependencies. IMO it's the most patronizing 'feature' D has. A year or
> so ago I ran into this issue during my first (and last) big project in
> D. Just last week I started working on it again and replaced everything
> that got initialized in a static constructor with stuff akin to
>
> static Foobar foobar(){
> static Foobar _foobar;
> static bool inited = false;
> if(!inited){
> _foobar = new Foobar();
> _foobar.init();
> inited = true;
> }
> return _foobar;
> }
You could move the static ctor into another module outside of the cycle
(e.g. the module where your main() function is). Then you get the same
effects as "platform" dependent initialization.
It would be very practical if D has a "lose" version of the static ctor,
that works even with cyclic dependencies. One could compare the module
names or so to make the ordering deterministic across all linkers/platforms.
PS: I wonder why it's not considered a problem to execute unittests in
random order? It's confusing if unittests fail "out of order", and the
high level test fails first, even if the actual error is in some other
low level module with its own unittests.
More information about the Digitalmars-d
mailing list