November 25, 2013
On Monday, 25 November 2013 at 09:39:14 UTC, ilya-stromberg wrote:
> On Monday, 25 November 2013 at 04:35:10 UTC, Andrei Alexandrescu wrote:
>> On 11/24/13 8:27 PM, Craig Dillabaugh wrote:
>>> Would it be possible to introduce a global scope of sorts that
>>> had to be explicitly referenced when one wanted to define or use
>>> a global variable. I haven't thought of how this might interface
>>> with other D features, but something along the lines of:
>>>
>>> @global int my_gobal_var; //Gets added to global scope.
>>>
>>> //Then any globals would have to be referenced as:
>>> global.my_global_var = 7;
>>>
>>> Makes for a bit of extra typing, and would mess with any module
>>> named 'global', but it might work?
>>
>> To put it bluntly, many things are possible but it seems the best is to do nothing here. We're in good shape.
>
> I personally like Craig Dillabaugh's sugestion. But we can use `.` operator for this because it alredy used for call global functions and, probably, should break nothing. Like this:
>
> int my_gobal_var;
>
> .my_global_var = 7;
>
> Is it possible?

Sorry if I didn't explain idea properly.

We can force using `.` before global variables. Almost everybody agree that use global variables is bad idea, so additional symbol looks acceptable.
November 25, 2013
On Monday, 25 November 2013 at 11:07:01 UTC, ilya-stromberg wrote:
>> int my_gobal_var;
>>
>> .my_global_var = 7;
>>
>> Is it possible?
>
> Sorry if I didn't explain idea properly.
>
> We can force using `.` before global variables. Almost everybody agree that use global variables is bad idea, so additional symbol looks acceptable.

And what to do with code already written? What exactly should be said to people who have to maintain the code? Do you volunteer to write a dmd/druntime/phobos pull?
November 25, 2013
On Monday, 25 November 2013 at 11:12:12 UTC, Maxim Fomin wrote:
> On Monday, 25 November 2013 at 11:07:01 UTC, ilya-stromberg wrote:
>>> int my_gobal_var;
>>>
>>> .my_global_var = 7;
>>>
>>> Is it possible?
>>
>> Sorry if I didn't explain idea properly.
>>
>> We can force using `.` before global variables. Almost everybody agree that use global variables is bad idea, so additional symbol looks acceptable.
>
> And what to do with code already written? What exactly should be said to people who have to maintain the code? Do you volunteer to write a dmd/druntime/phobos pull?

OK, I see.
November 25, 2013
On Monday, 25 November 2013 at 11:12:12 UTC, Maxim Fomin wrote:
> On Monday, 25 November 2013 at 11:07:01 UTC, ilya-stromberg wrote:
>>> int my_gobal_var;
>>>
>>> .my_global_var = 7;
>>>
>>> Is it possible?
>>
>> Sorry if I didn't explain idea properly.
>>
>> We can force using `.` before global variables. Almost everybody agree that use global variables is bad idea, so additional symbol looks acceptable.
>
> And what to do with code already written? What exactly should be said to people who have to maintain the code? Do you volunteer to write a dmd/druntime/phobos pull?

One of the things I had in mind with my idea at least, was that it could be introduced without breaking code, and would simply be a global scope (namespace) that folks could use to store their global variables. It would provide some additional safety/clarity for projects that wanted it.

Perhaps it could be implemented as a library (although that would likely preclude the exact syntax I showed). I don't feel I have the experience with D yet to implement such a thing. But maybe I will add it to my list of possible future projects.

November 26, 2013
On 11/25/13 1:39 AM, ilya-stromberg wrote:
> On Monday, 25 November 2013 at 04:35:10 UTC, Andrei Alexandrescu wrote:
>> On 11/24/13 8:27 PM, Craig Dillabaugh wrote:
>>> Would it be possible to introduce a global scope of sorts that
>>> had to be explicitly referenced when one wanted to define or use
>>> a global variable. I haven't thought of how this might interface
>>> with other D features, but something along the lines of:
>>>
>>> @global int my_gobal_var; //Gets added to global scope.
>>>
>>> //Then any globals would have to be referenced as:
>>> global.my_global_var = 7;
>>>
>>> Makes for a bit of extra typing, and would mess with any module
>>> named 'global', but it might work?
>>
>> To put it bluntly, many things are possible but it seems the best is
>> to do nothing here. We're in good shape.
>
> I personally like Craig Dillabaugh's sugestion. But we can use `.`
> operator for this because it alredy used for call global functions and,
> probably, should break nothing. Like this:
>
> int my_gobal_var;
>
> .my_global_var = 7;
>
> Is it possible?

Doesn't that work already?

Andrei
November 26, 2013
On 11/25/2013 4:05 PM, Andrei Alexandrescu wrote:
> On 11/25/13 1:39 AM, ilya-stromberg wrote:
>> I personally like Craig Dillabaugh's sugestion. But we can use `.`
>> operator for this because it alredy used for call global functions and,
>> probably, should break nothing. Like this:
>>
>> int my_gobal_var;
>>
>> .my_global_var = 7;
>>
>> Is it possible?
>
> Doesn't that work already?

Sure, but only because I saw the suggestion and traveled back in time to implement it!

November 26, 2013
On Tuesday, 26 November 2013 at 07:20:47 UTC, Walter Bright wrote:
> On 11/25/2013 4:05 PM, Andrei Alexandrescu wrote:
>> On 11/25/13 1:39 AM, ilya-stromberg wrote:
>>> int my_gobal_var;
>>>
>>> .my_global_var = 7;
>>>
>>> Is it possible?
>>
>> Doesn't that work already?
>
> Sure, but only because I saw the suggestion and traveled back in time to implement it!

I repeat, sorry if I didn't explain idea properly, see:
http://forum.dlang.org/thread/mydipbvhfjgvjybcyeyn@forum.dlang.org?page=6#post-sffdyogipcanorahdtte:40forum.dlang.org
November 26, 2013
On Tuesday, 26 November 2013 at 07:34:26 UTC, ilya-stromberg wrote:
> I repeat, sorry if I didn't explain idea properly, see:
> http://forum.dlang.org/thread/mydipbvhfjgvjybcyeyn@forum.dlang.org?page=6#post-sffdyogipcanorahdtte:40forum.dlang.org

Like Maxim explained, it's a breaking change to force it. Unfortunately, that just can't be done. This is one of those kinds of things that is self policing. If you really want to know when something is global when you use it then use g prepended before your global names. That's what a lot of people do to avoid this type of issue.
November 26, 2013
On Tuesday, 26 November 2013 at 08:01:23 UTC, Chris Cain wrote:
> On Tuesday, 26 November 2013 at 07:34:26 UTC, ilya-stromberg wrote:
>> I repeat, sorry if I didn't explain idea properly, see:
>> http://forum.dlang.org/thread/mydipbvhfjgvjybcyeyn@forum.dlang.org?page=6#post-sffdyogipcanorahdtte:40forum.dlang.org
>
> Like Maxim explained, it's a breaking change to force it. Unfortunately, that just can't be done. This is one of those kinds of things that is self policing. If you really want to know when something is global when you use it then use g prepended before your global names. That's what a lot of people do to avoid this type of issue.

Yes, I already understood this.
I just wanted to explain that already apologized for incomplete suggestion.
November 26, 2013
Chris Cain:

> If you really want to know when something is global when you use it then use g prepended before your global names. That's what a lot of people do to avoid this type of issue.

That is named "relying on hand-managed name conventions for something that could be the job of the compiler type system".

Bye,
bearophile