-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
global variables dropdown should check for all blocks instead of only top blocks #22
Comments
This is a bit of an unusual case. In most languages, global variables are created at the top-level of the program. This is the general practice because then you can clearly see where all the global variables are defined and initialized. Otherwise, they may be hidden in some deeply nested block. Moreover, it's possible that in some execution paths some global variable might be defined, but in others it won't be, which makes it even more difficult to reason about them and to understand and debug the program. JavaScript is an outlier in how Therefore, I would suggest that you switch to having your block introduce the variable as lexically scoped. Then the user can define their own top-level global variable and assign to it from within your block. |
Hi Mark,
Thanks for writing back.
I know that but i thought to make it more easier for the user to Use the ID
without creating An extra variable outside of the block.
E.g. to set it's property or create events listeners.
Thanks
…On Sun, 16 Jan 2022, 21:41 Mark Friedman, ***@***.***> wrote:
This is a bit of an unusual case. In most languages, global variables are
created at the top-level of the program. This is the general practice
because then you can clearly see where all the global variables are defined
and initialized. Otherwise, they may be hidden in some deeply nested block.
Moreover, it's possible that in some execution paths some global variable
might be defined, but in others it won't be, which makes it even more
difficult to reason about them and to understand and debug the program.
JavaScript is an outlier in how var works but in modern JavaScript
programming it is considered bad practice to use var in non-top-level
contexts.
Therefore, I would suggest that you switch to having your block introduce
the variable as lexically scoped. Then the user can define their own
top-level global variable and assign to it from within your block.
—
Reply to this email directly, view it on GitHub
<#22 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ANDG76OV2FDOMG7PV5UEMCDUWMUOJANCNFSM5MCT2KCQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Sure, I get that, but I think that the risks that I outlined generally outweigh that advantage for anything but the very simplest of programs. Even top-level global variables tend to get overused and unwieldy in many block programs. That said, your feature request is not completely unreasonable. Unfortunately, however, I'm afraid that it is unlikely to get implemented in the near future. |
Hi,
i have created a block that creates an element and then returns its ID as an global variable.
However this works fine unless the block is inside of an top block see video: https://drive.google.com/file/d/1zgOjPKQKnw8HbemuX8CskOFd0HbikZAt/view?usp=sharing
Thanks
The text was updated successfully, but these errors were encountered: