On Monday, 31 October 2016 at 18:46:31 UTC, Jonathan M Davis wrote:
though there's no reason to ever use a static constructor (shared or otherwise) when you can directly initialize the variable. It's really meant for more complicated initialization that can't be done directly.

Also, I would point out that in general, you'll be better off if you avoid static constructors and destructors. They can be extremely useful, but if multiple modules use them, and one imports the other (even indirectly), and the runtime thinks that that dependency is circular, then it'll throw an Error when you start your program (this comes from the fact that the runtime has to determine the order to run the static constructors so that everything is initialized before it's used, but it's not very smart about it, since it bases what it does solely on the presense of static constructors in a module and not what they actually do).

Thanks! This is probably why I was not able to find a good code example in github. Not that I tried very hard when search returned over 10K occurrences of "static this". Seems this kind of higher level reasoning is missing from the books and documentation that I've read. Hope this kind of knowledge gets recorded somewhere.

Reply via email to