Fake global associative array literals

Nick Sabalausky a at a.a
Fri Oct 28 14:30:46 PDT 2011


"bearophile" <bearophileHUGS at lycos.com> wrote in message 
news:j8eflp$q3o$1 at digitalmars.com...
> What do you think about a rewrite rule that changes code like:
>
> int[int] aa = [1:2, 3:4];
> void main() {}
>
>
> Into:
>
> int[int] aa;
> static this() {
>    aa = [1:2, 3:4];
> }
> void main() {}
>

You generally need to be very careful about adding module/static ctors, 
because they can easily lead to the dreaded circular ctor runtime error. So 
as nice as it would be to use AA initializers at the module-level, this 
carries a hidden danger which could be a royal PITA to debug (especially for 
D newbies), so I don't think it's a good thing to do.




More information about the Digitalmars-d-learn mailing list