jmoenig / Snap

a visual programming language inspired by Scratch
http://snap.berkeley.edu
GNU Affero General Public License v3.0
1.48k stars 739 forks source link

Scope Contrast #157

Closed cycomachead closed 10 years ago

cycomachead commented 10 years ago

Is there any plans to bring back the scope contrast function to Snap!?

jmoenig commented 10 years ago

Unlike BYOB Snap has a uniform scope, i.e. you can use any variable setter or getter block anywhere and it'll simply look up the value for its variable name in the current scope, so there is no need for scope contrast anymore. Is there a specific issue which you would like to address?

cycomachead commented 10 years ago

I've been seeing students name script variables and global var's the same name, and it can happen with block variables too. It would be nice to have the different coloring so you could tell which is which.

So, what happens when I create script variables which duplicate global variable names? Do the globals just take over? Do blocks have their own scope still?

jmoenig commented 10 years ago

In the case of same-named variables the nearest lexically scoped one precedes outer scopes. In your example the script var takes precedence over the others:

script vars -> parameters (if any) -> sprite local vars -> globals

make sense?

cycomachead commented 10 years ago

Yeah, makes sense. That sounds right.

I can't remember the example I was working through with a student today, though it was a little messy.

Though, I will say it was cool to just delete the script variables block and not need to make changes and have code run! :)

jmoenig commented 10 years ago

Okay, I think this has been resolved - we no longer have conflicting scopes in Snap as we used to have in BYOB - I'm closing this issue. Thanks!