FWIW, I fear that the cure proposed here may be worse than the disease. It seems to me that fundamentally, the confusion out of which all the discourse/stackoverflow questions arise stems from the fact that the meaning of “x=1” depends on the context in which it appears (at top level scope or in a loop). The solution proposed here (whether the original one or its modifications) makes this context dependence even more subtle; while it addresses the most common cases in a DWIM way, these subtleties may well lead to even more confusion in more complex/corner cases down the road.
In the spirit of explicit is better than implicit, maybe the following, perhaps radical, solution is a way to address the fundamental issue: KEEP the current (1.0) behavior, except for one change: declaring or modifying, but not reading, a global variable ALWAYS requires a
global annotation; hence
x=1 at top level scope is an ERROR (with an exception for functions perhaps).
x=1 in local scope ALWAYS creates/modifies a local.
The advantage of this is its simplicity, which leaves very little room for confusion. Beginners could just be told that this is how variables are declared in Julia. If they try the likes of
x += 1
they still get an error, but the error now appears at “x=1”, with an explicit hint to use
global. This is a lot less confusing than the current
x not defined. Similarly, code pasted from a function will still not work when pasted to the REPL, but at least you get a very clear error message. A possible knock-on effect is that this might reduce the number of issues where people benchmark in global scope.