# 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:** 12
**Page:** 12

<div class="post-metadata">

### Author: ![peter.derijk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peter.derijk/32/8770_2.png) [@peter.derijk](https://discourse.julialang.org/u/peter.derijk)
#### Post date: [October 11, 2018, 8:14pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/223 "2018-10-11T20:14:52Z")

</div>

I have taught absolute beginners (other languages) and is indeed not really that difficult to introduce scope to them in a way they understand IF you can do it at the appropriate time (i.e. when introducing functions), and if it is a the version of scope as implemented in any other language:  
You generally start with operators, variables and loops. Assigning something to a variable and then doing something with it in a loop is an extremely common pattern (I am convinced, even without checking, that the v1 change invalidated code in the majority of pre v1 tutorials). Having to explain that they have to use global to access the variable right in front of loop (for no apparent reason) is going to be difficult. The easy place to explain scope is functions: you have a separate piece of code that you are calling from another location, so there it is logical that the variables are contained to that part. You are also giving the values from your current location/scope needed by the function as parameters. One of the worst things of v1 scope then is that at this point you are going to have to explain that what they learned in the beginning (putting globals to get at the variable in front of the loop) does not apply if you put it in a function.

Some of the other suggestions here are even more complex and difficult to explain than v1. In my experience, if I start needing a lot of exceptions and lengthy explanations, I am usually on the wrong track (KISS principle). The original proposal by @jeff.bezanson is simple and consistent, and poses a very limited amount of incompatiblity.

---

<div class="post-metadata">

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

</div>

Adding my 2c to the teaching discussion, particularly fresh since I’m just wrapping up teaching an intro computing course for biologists in python.

My experience is that students, esp in an intro course, will take a lot on faith. All the syntax they’re learning is new, all the concepts are new. If you tell them that `for` is spelled `global for`, they’ll do it until you tell them to do otherwise. No one asked for example why it’s `print(string)` but `string.split()`.

For the particularly curious students you can say, “great question - it’s not critical that you understand right now, but Google ‘scope’ if you’re interested in learning more, or stop by office hours.”

I don’t have a strong opinion on the underlying merits of the different ideas. I got bit by this early in the transition, but adapted quickly. Given how great the language design is generally, and how much time the core devs think and reason about the decisions0 (a fact which has become even more glaringly obvious in the last 6 weeks teaching python, which I used to think was fine), my inclination would be to trust the reasons for the design as implemented. More informative error messages are always great of course.

---

<div class="post-metadata">

### Author: ![Wenjie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wenjie/32/10123_2.png) [@Wenjie](https://discourse.julialang.org/u/Wenjie)
#### Post date: [October 12, 2018, 1:56pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/225 "2018-10-12T13:56:44Z")

</div>

> [@tim.holy](#):
>
> If the bug you’re investigating is triggered in a project that imports ~500 packages at once, this ability is important.

Late to the party here. I just want to add some importance to the quote above. Packages are not the only things imported, _datasets_ too. Big data analysts need to import data of 10G or even 100G into the memory; it will be a nightmare for them to keep restarting the program.

---

<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 14, 2018, 5:50pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/227 "2018-10-14T17:50:11Z")

</div>

This hasn’t changed and has always behaved like this; `do` syntax is just shorthand for passing an anonymous function to a higher order function. (Your code also doesn’t make much sense as far as I can tell—which `m` is supposed to persist outside?)

---

<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 14, 2018, 5:58pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/228 "2018-10-14T17:58:00Z")

</div>

Sorry I had to check what is OP saying! 😕 I will delete this message too to not spoil this topic…

---

<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 14, 2018, 5:58pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/229 "2018-10-14T17:58:52Z")

</div>

No problem! I wouldn’t worry about spoiling the thread or deleting anything, I think we’ve gotten the feedback we need at this point.

---

<div class="post-metadata">

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

</div>

> [@StefanKarpinski](#):
>
> I think we’ve gotten the feedback we need at this point.

Now that the debate seems to be cooled down, I would like to say that, when the devs feel that they have a clear roadmap and are confident with the eventual solution, I would love to read a blog post or some other kind of document explaining this point, and what we can expect in future versions of Julia, even before the changes are implemented.

Ideally, with hints for people who develop teaching materials, about how the issue might be approached to avoid misunderstandings.

I think that this will help to have users prepared for the changes, and will make the transition less messy.

---

<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 22, 2018, 8:32pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/231 "2018-10-22T20:32:19Z")

</div>

I’ve come up with a different solution that is non-breaking and solves the issue less drastically while retaining the benefits of the current design. I will write it up in a new thread and link to it from here.

---

<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 23, 2018, 9:00pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/232 "2018-10-23T21:00:03Z")

</div>

The proposal for my new solution is here:

> [@New scope solution](https://discourse.julialang.org/t/new-scope-solution/16707):
>
> I have an alternate, non-breaking solution to the scope issue previously discussed on [discourse](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894) and [github](https://github.com/JuliaLang/julia/issues/28789). The new potential solution is the following rule to decide whether a variable, x, which is not marked as explicitly local or glogal and which is assigned to in a top-level scope construct is local or global: x is global if it is accessed before being assigned on all paths through the scope body. In other words, x is local unless there’s no way it could make sense for it to be local. Or…

---

<div class="post-metadata">

### Author: ![Vic](https://avatars.discourse-cdn.com/v4/letter/v/9e8a1a/32.png) [@Vic](https://discourse.julialang.org/u/Vic)
#### Post date: [November 6, 2018, 3:11pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/233 "2018-11-06T15:11:44Z")

</div>

Coincidentally, I’ve suggested essentially [the same idea here](https://discourse.julialang.org/t/explicit-denotation-of-variability-and-immutability/8686/99)

@haberdashPI

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [November 6, 2018, 3:54pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/235 "2018-11-06T15:54:01Z")

</div>

Let’s try to keep the conversations around this topic organized — the latest discussion is happening in the [New scope solution](https://discourse.julialang.org/t/new-scope-solution/16707) thread. I’m going to close this topic in favor of that one.

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [November 6, 2018, 3:54pm UTC](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/236 "2018-11-06T15:54:12Z")

</div>



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