order of static constructor execution

Russell Lewis webmaster at villagersonline.com
Wed Mar 17 10:00:22 PDT 2010


Walter Bright wrote:
> So, I propose the following:
> 
> 1. Attempt the depth-first traversal of the static constructors.
> 
> 2. If a loop is detected, rather than issuing an error message, simply 
> arbitrarily pick one order and continue constructing.

I'm of the camp that "if it's broken, the programmer needs to fix it." 
Why not just include this as an optional flag on the import statement?

import __dependency__ foo.bar.baz;

The __dependency__ flag means that if there exists a loop which involves 
both this module and foo.bar.baz, then foo.bar.baz should be initialized 
first.  (Contradictory flags would be an error.)

Russ



More information about the Digitalmars-d mailing list