November 29, 2012
On Thursday, 29 November 2012 at 14:17:40 UTC, Andrei Alexandrescu wrote:
> On 11/29/12 6:44 AM, foobar wrote:
>> On Thursday, 29 November 2012 at 10:25:40 UTC, Walter Bright wrote:
>>> On 11/29/2012 6:40 PM, Jacob Carlborg wrote:
>>>> On 2012-11-29 03:00, Walter Bright wrote:
>>>>
>>>>> An attribute would bring along with it the notion of having some static
>>>>> constructors care about dependencies and others not. A pragma would be
>>>>> global to the module.
>>>>
>>>> Why can't the attribute be global to the module?
>>>>
>>>
>>> Because attributes attach to the declarations they enclose. A global
>>> attribute would be something else.
>>
>> What's wrong with attaching the annotation to the module declaration?
>> i.e.
>> @no_circular_ctors module foobar;
>
> I think this entire approach is unprincipled (aside from solving a problem that's not urgent and not important). We shouldn't focus on the _syntax_ of the completely unprincipled approach, but instead on improving it.
>
> A possibly better approach would be e.g. to do a simple analysis of the static constructor's use of symbols, and use that set to decide whether two static constructors must be ordered or not.
>
>
> Andrei

Huh?
I made the exact same observation you did that module declarations can also carry attributes. You completely ignored the main part of my post regarding what I feel would indeed be a better approach (IMO).

I don't understand why you bother to answer a post you haven't bothered to read.
November 29, 2012
On 2012-11-29 20:48, Andrei Alexandrescu wrote:

> You can't say that. They do work don't they.

I think he means, not for the use cases we discuss here.

-- 
/Jacob Carlborg
November 29, 2012
On 2012-11-29 18:35, Andrei Alexandrescu wrote:

> There are plenty of patterns for solving order of initialization issues
> in libraries, known since time immemorial. Requiring a library
> initialization call would be the simplest (albeit not the most elegant).
> The Monostate and Singleton patterns also come to mind.
>
> This is just not something that has no solution. Better solutions are
> always welcome, but keeping a baseline is always useful.

Another standard solution is to use functions which lazily initialize some value.

-- 
/Jacob Carlborg
November 29, 2012
On 11/29/12 3:27 PM, foobar wrote:
> Huh?
> I made the exact same observation you did that module declarations can
> also carry attributes. You completely ignored the main part of my post
> regarding what I feel would indeed be a better approach (IMO).
>
> I don't understand why you bother to answer a post you haven't bothered
> to read.

Got it, apologies.

Andrei
November 30, 2012
On 11/30/2012 5:33 AM, deadalnix wrote:
> Cowabunga ! String as attribute again.

Did someone say "Wil Wheaton" 3 times? <g>
November 30, 2012
On 11/30/2012 1:17 AM, Andrei Alexandrescu wrote:
> A possibly better approach would be e.g. to do a simple analysis of the
> static constructor's use of symbols, and use that set to decide whether
> two static constructors must be ordered or not.

It's not a complete solution, since using a symbol S from module A does not necessarily mean dependency on S being statically constructed in A. But it would be a start.

November 30, 2012
On 11/30/2012 12:58 AM, Andrei Alexandrescu wrote:
>> Because attributes attach to the declarations they enclose. A global
>> attribute would be something else.
>
> Could be attached to the module declaration.

That implies that "module" no longer must be first, it could appear elsewhere. It also implies that "module" becomes an actual declaration, rather than its own construct. It also implies that this attribute must be decided explicitly and in advance by the programmer, it cannot be added via a mixin from elsewhere.

Pragma just seems more suitable to declaring global things.

November 30, 2012
On 2012-11-30 03:39, Walter Bright wrote:

> It's not a complete solution, since using a symbol S from module A does
> not necessarily mean dependency on S being statically constructed in A.
> But it would be a start.

Well, not using any symbol from module A means it has no dependency for sure on A in the static constructor.

-- 
/Jacob Carlborg
November 30, 2012
On 11/29/12 9:39 PM, Walter Bright wrote:
> On 11/30/2012 1:17 AM, Andrei Alexandrescu wrote:
>> A possibly better approach would be e.g. to do a simple analysis of the
>> static constructor's use of symbols, and use that set to decide whether
>> two static constructors must be ordered or not.
>
> It's not a complete solution, since using a symbol S from module A does
> not necessarily mean dependency on S being statically constructed in A.
> But it would be a start.

From what I see it would solve most problems there are out there, 100% automatically, without any syntax addition, and without any downside risk.

Andrei
November 30, 2012
On 11/30/12 3:12 AM, Jacob Carlborg wrote:
> On 2012-11-30 03:39, Walter Bright wrote:
>
>> It's not a complete solution, since using a symbol S from module A does
>> not necessarily mean dependency on S being statically constructed in A.
>> But it would be a start.
>
> Well, not using any symbol from module A means it has no dependency for
> sure on A in the static constructor.

Exactly. It would be the sensible thing to do. It would disallow only modules with static constructors that use stuff in other modules with static constructors. Though that is still conservative, it would catch a vast majority of cases with a simple and easy to understand policy.

Andrei