I debated bringing this up, but I fear if I don’t it will just keep rattling around in my head. I suspect the answer will be “The upheaval from this change would be too much”, so I’m not really expecting it to go into 2.0 but maybe it should be considered.
I’ve been reading github issues on global variable scoping specifically:
And @jeff.bezanson made the comment:
Do you want to write
var x = 0
to introduce every variable? That would also “fix” this, and be more like other languages.
And I feel like the decision to NOT have to declare the variable before hand is causing this issue.
I’ve spent my entire adult life (and some of my teen years) putting something in front of a variable assignment to let the compiler know I’m defining a variable for this scope. Whether is be “int”, “var”, “let” or now with Julia “local” and I never found it that onerous. Hence the reason I put local
in front of all my variable declarations.
I’m assuming one of the reasons to not require local in front of a variable declaration was because “It was obvious you where declaring a variable with the assignment”. However the issues raise show that is not obvious, sometimes you want to change a variable in a parent scope and sometimes you want to declare a new variable…the compiler can only infer what the developer wanted.
So requiring that when declaring a new variable you prefix it with local would clear up the confusion for the compiler, if the assignment wasn’t prefixed with local, and if the variable is not defined in a parent scope, it’s a variable not found, otherwise it’s a new variable.
All that being said it is nice in the REPL to be able to declare a variable just with the assignment. I tend to view the global scope as special anyway not that it’s global but that it appears global because it just happens to be the parent of all other scopes. So having the global scope not require local/global or ignoring them if they are included doesn’t cause a concern with me. Using local in the global scope is meaningless because there is no parent scope to keep separate from.
Thanks for listening, feel free to tell me I’m nuts.