Random D geekout

Nick Sabalausky SeeWebsiteToContactMe at semitwist.com
Sun Apr 22 22:47:23 PDT 2012


"H. S. Teoh" <hsteoh at quickfur.ath.cx> wrote in message 
news:mailman.2061.1335131543.4860.digitalmars-d at puremagic.com...
>
> It's my fault. I really should be using module globals for those
> regexes, and a module ctor (static this) for initializing them.
>

In most cases, I've come to prefer lazy initalization (via a module-level 
@property) over module ctors because:

1. If it never actually gets used, you avoid adding extra processing at 
startup merely because you imported some module.

2. It decreases the risk of hitting the dreaded cyclic-module-dependency 
error (major PITA).

And if you do want to throw away #1 and force initialization upon startup, 
you can still do that by simply accessing it at the beginning of main.

I've always felt module ctors were a great idea, but after hitting the 
cyclic dependency issue enough times (or even just the first time), I've 
come to think they're, unfortunately, best avoided.




More information about the Digitalmars-d mailing list