Once we drag a procedures block to workspace and rename it to "foo", there will be a new "do foo" block appear in the panel.
And if you set a variable 'x' in workspace , there will be "set x/get x" block in workspace. (panel now contains: set[item], get [item], set x, get x)
My proposal is majorly effect the variable panel:
1. Once we drag a procedures block to workspace and rename it to "foo", there will be a new "do foo" block appear in the panel. (same as current blockly behavior)
2. AND blockly will generate new "set foo:[item]/get foo:[item]" blocks in the variables panel, just below the default "set [item]/get [item]" blocks. (panel now contains: set[item], get [item], set foo:[item], get foo:[item], set x, get x)
3. Once we drag a "set foo:[item]" block into workspace, it will be restricted to only able to be connected in the 'foo' procedure.
4. The foo:item name array will be separate from global set variables array. if we rename foo:'item' to 'y', the "set foo:y/get foo:y" blocks will appear in the panel.
(panel now contains: set[item], get [item], set foo:[item], get foo:[item], set x, get x, set foo:y, get foo:y)
sorry gasolin
but i did miss your initial response
i think your close but i need a example because i not sure how "set foo:" would apply
my point is that functions should be isolated and not be able to change the global variables
now class methods are the allowed to change the class variables status
kind regards,RobrechtOn Thursday, October 25, 2012 3:16:34 AM UTC+2, Neil Fraser wrote:It's time to think about how to handle scope properly in Blockly. I'm looking for input.As software engineers it is blatantly obvious to us what we expect should happen. All languages have the same language scoping rules at a gross level. But I've been trying to avoid falling into the trap of just doing what other languages do simply because that's what other languages do. Blockly is designed to be simpler and more intuitive. Maybe conventional scoping is the right way to do it, but I really want to think through alternatives before falling into that rut.Let's start by gathering a list of options. Forget about what's intuitive or feasible or compatible.* All globals.Blockly is mostly like this, but to really be all global we'd need to global-ize the procedure arguments. Exported code could translate this:var a, b;add(1, 2);function add(a, b) {return a + b;}to this:var a, b;
--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Hi Mikhail,
yes, we agree on that. I think we disagree on how we see Blockly. I
see it as a toolkit to create other applications. Those other
applications could be teaching tools, and can be created at the
different levels of presentation that you talk about for students. .
One more time I would challenge declared in Philosophy problem for beginners with local variables. The concept of local variable is rather simple ("first name").
I second the idea to encourage users to use limited-scope variables. This is not a condemnation of global variables, just a voiced support of another paradigm of development.
In order to accomplish this, I suggest that blocks which create "code blocks" (e.g. loops, if/then, procedures, etc.) have a top section where local-scoped variables would be defined. Yes, it hearkens back to the day of declaring all of your variables at the top of the procedure, but it cleanly delineates the variable declaration from the rest of the code...
--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi Neil,I think it's important to highlight your future vision for Blockly to help guide this process. In software there are many right answers and which is better often depends on the context - it's a common issue that the meaning behind why something is as it is, is lost or altered because the original reason for doing something isn't recorded. I'm looking at a lot of this from an embedded hardware point of view and my reasons and priorities will undoubtedly differ.Ultimately, I feel that if the scope of Blockly projects are ever to grow, the use of local variables is unavoidable, whether this be via a special block or is implicitly implied. For educational purposes, I don't see why the existing behaviour can't be emulated through a flag setting, after all, all variables global is a fairly straight-forward paradigm.As an initial thought, a potentially cleaner approach, not dissimilar to MIT App Inventor, could be to promote variables to global context:
- Normal local variables, which are likely more numerous, wouldn't need any kind of special identification, keeping the block view clean.
- The user can assume all variables to be local only unless told otherwise, keeping the paradigm simple.
- The Global Promote could potentially be placed outside of program flow, allowing for users to arrange their globals together visually, separate from their other code, keeping flow clean and globals well-tracked, a possible best-practise.
- You can avoid basic scoping issues by pre-pending variable names with the local function name if they are not globally promoted when generating code for languages where this is an issue.
--
Sorry, I was just trying to understand your previous comment. In the approach I suggest, variables are defined when they're first set as they currently are in Blockly (keeping the simplicity), at which point they are local to the function/proc/event they're defined in, there are no extra steps or blocks such as initialize local, keeping the paradigm and program flow nice and simple until you WANT a global, then you have to do the one extra step of declaring a global.
--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+unsubscribe@googlegroups.com.
It's time to think about how to handle scope properly in Blockly. I'm looking for input.