Another possible solution to the global scope debacle

Would it be possible to just re-introduce the warning/error messages in the REPL but otherwise keep the new behaviour from #19324?

In this way, the examples (IanNZ / 28789) loose their gravity as the error/warning message just tells me what to do, i.e. prepend the variable with global. The silent failure gives a warning, the ‘real’ failure an error, for example:

julia> for i in 1:2
         beforefor = false
       end
┌ Warning: `implicit assignment to global variable `beforefor``.
│ Use `global beforefor` instead.
└

julia> for file in list_of_files
         # fake read file
         lines_in_file = 5
         total_lines += lines_in_file
       end
┌ Error: `implicit assignment to global variable `total_lines``.
│ Use `global total_lines` instead.
└

I’m not sure I like (yet?) the need to write global at some places but on the other hand it seems a coherent rule to access global variables and loosing the hard/soft scope distinction was nice (this distinction has also been criticized). But more importantly, I think the current behaviour has been choosen and I don’t hope that there is now a rush to change it again (before 2.0 and after careful consideration)!

8 Likes