thunkable / thunkable-issues

24 stars 9 forks source link

Local variables needed in functions (help variables, temp variables, etc) #352

Open fastpipe opened 4 years ago

fastpipe commented 4 years ago

The situation:

You create a function with parameters and a result. Inside the function block you have to calculate several values by help variables (temporary variables, not needed outside). It is a logic catastrophe to use global (app) variables for this. And in bigger projects you loose overview. Global variables only created for temporary use in function can cause severe problems, when you use the same name outside the function.

Of course you could implement additional parameters to use them as local variables. But that is not a proper solution. Or you can construct a count loop that you do not use and use the names of the loop variables. But this is no real solution, because count-variables in loops also react global. What do you think?

So we urgently need local variables!

As a teacher for computer science and book author I have problems to teach about functions and using global variables.

MrMazzone commented 4 years ago

@fastpipe Absolutely agree! -- Also a teacher FYI. I just completed a unit on function/procedural abstraction. I didn't like having to use global/app variables to just temporarily store values for the function to just return.

Initializing local variables would be a welcomed addition. Could be done similar to App Inventor where the block showcases the variable scope and lifetime. image

mark-friedman commented 4 years ago

Thanks @fastpipe and @MrMazzone! We have local variables on our feature list and understand how useful they can be.