Summary
In my opinion ...
- The scope of script variables and upvars is unnecessarily wide for practical use.
- It goes against Snap!'s design philosophy.
- It is a source of unnecessary error.
Therefore I propose to limit the scope of both script variables and upvars to 'local'.
The scope of script variables and upvars is unnecessarily wide for practical use
Consider the following block:
In this block "number" is a local counter, and its value is relevant inside the FOR-block only. Even so it exists inside the entire script that this FOR-block is a part of.
Edit: initially here was a parapraph about variables being available above the SCRIPT VARIABLES block in which they are declared. On closer inspection I found the latter to be false, and (since I don’t want to cause confusion) I removed the parapraph.
Another case:
In this case, as well, there's no use for variable "store" to be available outside the IF-block. If there were, it should be declared at a higher hierarchical level within the code / environment.
It goes against Snap!'s design philosophy
From what I have understood Snap!'s design philosophy is mostly a mix of functional and OO paradigma's. Both are characterized by implementation abstraction, the latter implying local data wherever possible.
I've been doing some reading in the venerated SICP , and I'm sure the authors would agree. Admittedly this is an argumentum ab auctoritate (which Wikipedia calls a fallacy) - and even worse, I invented it - but I guess you catch the drift.
It is a source of unnecessary error
Suppose within the environment of the aforementioned FOR-block a (global, sprite or script) variable called "number" already existed, like in the following example:
Guess what it reports ... 11.
If the variable "number" is going to be used again somewhere down the script, the programmer will probably have assumed that its value is still 123 (or whatever it was after the "various operations and stuff"), which in reality it isn't: an unnecessary source of error.
Therefore I propose to limit the scope of both script variables and upvars to 'local'.
That is: a variable will be avaliable only within the scope of the structure it is declared in.
Is it an urgent and necessary change? No. But it would be a wise change (I think).