Michel Fortin wrote:
I'd like to point out that the trick of creating a separate module to
initialize another one is not much safer than C++ static initialization.
Take for instance std.stdio which it is initialized by std.stdiobase's
static constructor. If your module import std.stdio and attempt to use
the standard input/output/error streams in a static constructor, there
is no guaranty that std.stdiobase static constructor will have been
called before yours (unless you also import std.stdiobase). It might end
up crashing depending on link order.
If your module imports std.stdio, std.stdiobase's static constructor is
guaranteed to run before your module's static constructors because your
module depends on std.stdiobase indirectly via std.studio.
So it's a clever trick allowing you to bypass the safety checks, but
it's still dangerous, and it's not usable for templates and mixins.