# Another possible solution to the global scope debacle

**URL:** https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894
**Category:** Internals & Design
**Created:** [October 4, 2018, 6:14pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894 "2018-10-04T18:14:07Z")
**Posts on this page:** 20
**Page:** 2

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [October 4, 2018, 8:44pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/21 "2018-10-04T20:44:42Z")

</div>

That’s the purpose of having a warning in 1.1 and an error in 1.2 and only changing the behavior in 1.3: anyone who upgrades to either 1.1 or 1.2 would get detailed advance warning of the change. Even the people who hate to fix deprecation warnings and just ignore them in 1.1 would get a hard error and be forced to change their code in 1.2. There is some chance of someone going straight from 1.0 to 1.3, skipping both 1.1 and 1.2, and never reading anything on discourse or the release announcements for any Julia versions, but that seems like an acceptable risk.

---

<div class="post-metadata">

### Author: ![laborg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laborg/32/5474_2.png) [@laborg](https://discourse.julialang.org/u/laborg)
#### Post date: [October 4, 2018, 8:53pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/22 "2018-10-04T20:53:20Z")

</div>

Is it still on the table to do nothing?  
For me its always more complicated to adopt to a changed behaviour than to learn a new concept and for this reason I predict that the proposed solution of transitioning the behaviour over multiple version will cause more confusion than the problem itself does now. People already get angry because they can’t find `linspace` in 1.0, not to think of the ruckus that will ensue after 3? different behaviours will have been described in Wikis/Tutorials/Books/Manuals/Blogs…

---

<div class="post-metadata">

### Author: ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)
#### Post date: [October 4, 2018, 9:00pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/23 "2018-10-04T21:00:27Z")

</div>

Personally I don’t mind too much unless I’m required to have `local` or `global` in front of my variables. I have a lot of scripts with a lot of variables and having that kind of annotation to be mandatory wouldn’t be great.

```julia
local data = load_data()
global results = process(data)
local plots = plot(results)

```

In the strategy above I would have to skip Julia 1.2 (which I guess would be fine?).

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [October 4, 2018, 9:10pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/24 "2018-10-04T21:10:53Z")

</div>

Unless that code is in a loop or other scope construct, none of those would require annotations.

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [October 4, 2018, 9:11pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/25 "2018-10-04T21:11:36Z")

</div>

This change isn’t breaking if it’s a bugfix? I think a lot of people ran into this thinking it was a bug? This hits on the whole “what is a bugfix” really isn’t well-defined.

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [October 4, 2018, 9:12pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/26 "2018-10-04T21:12:03Z")

</div>

Given the amount of pushback and confusion that we’ve been getting because of the new scope behavior, I’d say not. I don’t much fancy having to deal with multiple people per day posting questions about this.

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [October 4, 2018, 9:12pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/27 "2018-10-04T21:12:38Z")

</div>

Calling this a bug fix would be disingenuous since it was very much intended and documented.

---

<div class="post-metadata">

### Author: ![jeff.bezanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff.bezanson/32/48_2.png) [@jeff.bezanson](https://discourse.julialang.org/u/jeff.bezanson)
#### Post date: [October 4, 2018, 9:17pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/28 "2018-10-04T21:17:34Z")

</div>

Yes, sometimes it’s difficult to say what counts as a bug fix. A good example is my recent PR that fixes a segfault, but also introduces new method ambiguities. But this is not one of those cases. This may be a fix in the sense that it changes something you greatly dislike, but the current behavior does not block anybody from getting work done (your code can still work, you just don’t like the way it looks), and changing it could absolutely make programs stop working, so it’s a breaking change.

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [October 4, 2018, 9:24pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/29 "2018-10-04T21:24:53Z")

</div>

> [@StefanKarpinski](#):
>
> it was very much intended and documented.

Ah, I thought it was an unintended consequence found after the release.

---

<div class="post-metadata">

### Author: ![bjarthur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bjarthur/32/9638_2.png) [@bjarthur](https://discourse.julialang.org/u/bjarthur)
#### Post date: [October 4, 2018, 9:25pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/30 "2018-10-04T21:25:25Z")

</div>

i seriously hope that 2.0 is not “years away”. how about next summer instead? what other breaking changes are being discussed?

my inclination would be to just suck it up, no breaking changes until 2.0, and sleep in the bed we made for ourselves by not having a longer transition between 0.7 and 1.0. hopefully we can learn from this experience.

---

<div class="post-metadata">

### Author: ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)
#### Post date: [October 4, 2018, 9:40pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/31 "2018-10-04T21:40:31Z")

</div>

I read through the comments on GitHub in the related issue and I think I can express better now what I meant by my examples. One of the main features why I understood the change is introduced it is that people want to copy-paste code between global scope and functions (e.g. when using examples from forums in their code).

Currently such copy-pasting produces an error in some cases. After this change it will work, but on the other hand silently produce a different behavior in some other cases. And although an error case (current functionality) is annoying at least it manifests itself visibly (you add `global` where needed and re-run the code which is cheap in interactive mode), while silently different behavior between function and global scope may lead to bugs.

Therefore - apart from a general rule (which I agree is clear) - I thought that having a reference somewhere that lists those cases would be good.

---

<div class="post-metadata">

### Author: ![Rui](https://avatars.discourse-cdn.com/v4/letter/r/ba8739/32.png) [@Rui](https://discourse.julialang.org/u/Rui)
#### Post date: [October 4, 2018, 9:43pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/32 "2018-10-04T21:43:13Z")

</div>

I suspect this thread will be quite messy if we don’t focus only on people’s opinions about the final design proposal.

---

<div class="post-metadata">

### Author: ![jeff.bezanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff.bezanson/32/48_2.png) [@jeff.bezanson](https://discourse.julialang.org/u/jeff.bezanson)
#### Post date: [October 4, 2018, 9:45pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/33 "2018-10-04T21:45:11Z")

</div>

Yes, thank you. For example if we want this design, we could consider enabling it in the REPL first and everywhere in 2.0.

---

<div class="post-metadata">

### Author: ![Liso](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Liso](https://discourse.julialang.org/u/Liso)
#### Post date: [October 4, 2018, 10:02pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/34 "2018-10-04T22:02:22Z")

</div>

> [@Rui](#):
>
> I suspect this thread will be quite messy if doesn’t just focus on people’s opinions on whether the design proposal is the “right thing”.

But donn’t we have actual problem because we were focused too much to one point of view? Maybe we could start to give more time to found best solution?

---

<div class="post-metadata">

### Author: ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)
#### Post date: [October 4, 2018, 10:04pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/35 "2018-10-04T22:04:20Z")

</div>

I don’t know if it violates any assurance, but I’d prefer to see (a) do it in the REPL, (b) do the rest in 1.1.0 (or 1.2.0 – whatever makes sense viz a viz deprecation). Waiting for 2.0 makes little sense to me – it means engraining the problematic behavior in people’s understanding of Julia.

---

<div class="post-metadata">

### Author: ![jeff.bezanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff.bezanson/32/48_2.png) [@jeff.bezanson](https://discourse.julialang.org/u/jeff.bezanson)
#### Post date: [October 4, 2018, 10:04pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/36 "2018-10-04T22:04:30Z")

</div>

Ok, propose another solution. No time limit.

---

<div class="post-metadata">

### Author: ![Liso](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Liso](https://discourse.julialang.org/u/Liso)
#### Post date: [October 4, 2018, 10:06pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/37 "2018-10-04T22:06:09Z")

</div>

> [@StefanKarpinski](#):
>
> That’s the purpose of having a warning in 1.1 and an error in 1.2 and only changing the behavior in 1.3: anyone who upgrades to either 1.1 or 1.2 would get detailed advance warning of the change.

If we know the future that will come, isn’t something analogous to python’s `from __future__ import scope_behavior` possible in Julia 1.1 too?

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [October 4, 2018, 10:06pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/38 "2018-10-04T22:06:48Z")

</div>

> [@ChrisRackauckas](#):
>
> Ah, I thought it was an unintended consequence found after the release.

No, very much intentional:

> <https://github.com/JuliaLang/julia/pull/19324>
>
> This PR examines the impact of deprecating (much of?) the distinction between ha…rd/soft scope. Instead it simply distinguishes between global and local scope. This means that all scope-blocks introduce the same type of scope (local), rather than distinguishing that toplevel functions have special, hard scope rules. I've updated the manual to try to show how this change would impact the user. The main change is that there would no longer be the concept of implicit globals computed from examining the module bindings. Instead the global/local computation would be purely syntactic. For example, take the following code snippet:
> 
> \`\`\`julia
> global x = 0
> for x = 1:10 end
> @show x
> \`\`\`
> 
> Under the current, this shows \`10\`, because \`x\` had a value before the for-loop.
> Under the new rules, this shows \`0\`, since the for-loop introduce a new local scope.
> 
> Making this code work as before would requiring declaring \`x\` to be a global inside the for-loop scope block:
> \`\`\`julia
> for x = 1:10; global x; end
> \`\`\`
> 
> Another option that this PR still permits is to make an assignment to x inside a begin/end block:
> \`\`\`julia
> begin
> x = 0
> for x = 1:10 end
> end
> @show x
> \`\`\`
> 
> The impact to base is small (two corrections to code that will be broken anyways when #265 is fixed).
> 
> The impact to tests is larger, as it takes a large number of unintentionally-global variables and causes them to emit a deprecation warning. I think the resulting changes are arguably beneficial, even if we don't decide to change the scoping rules, since they reduce the number of objects being kept around in global variables.

---

<div class="post-metadata">

### Author: ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)
#### Post date: [October 4, 2018, 10:11pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/39 "2018-10-04T22:11:45Z")

</div>

Is there so to speak a “right” solution, irrespective of cost or impact on the user community?

---

<div class="post-metadata">

### Author: ![jeff.bezanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff.bezanson/32/48_2.png) [@jeff.bezanson](https://discourse.julialang.org/u/jeff.bezanson)
#### Post date: [October 4, 2018, 10:12pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/40 "2018-10-04T22:12:19Z")

</div>

Yes, adding a way to opt-in to the future behavior makes sense.

[Previous page](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894.md?page=1)

[Next page](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894.md?page=3)
