Using C-Blocks for object scope? #1403
reesericci
started this conversation in
General
Replies: 1 comment 4 replies
-
if you want stuff to run independently from the main script use pushThread |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Coming from Ruby, blocks are used plenty for controlling scope, and I think it makes it clear what objects are in use. Here's an example Rails database migration:
This puts the t object, the products table, in scope for that block, which I think is cleaner instead of a series of commands like
add_column :products :name :string
where the column needs to be specified every time, or something likeswitch_table
(fictional) before running commands.Coming back to Scratch, I find myself wanting to do similar scope controls while working on turbowarp.sh. Here's an example: I want to have it be possible to use multiple ttys "contexts" for running commands within one script. I briefly considered starting a new context on every script, like an event block, but that doesn't make sense. I could add a switch tty block, but it's just not as elegant as what a c block would be. Here's a picture with comment blocks (it also has some new expect stuff i'm working on):
This allows for a few things:
Allowing for extraneous scripts to run independently of a global context, like the apt install - but a better example is if it was flipped, where the ls was in the C-block and the apt install was running globally.
Discarding the TTY at the end of the script automatically, instead of doing it with a when stop button click or just leaving it open until a new connection
Making it incredibly clear which TTY is in use, and reducing shared state
What are y'alls thoughts on this?
Thanks,
--reese
Beta Was this translation helpful? Give feedback.
All reactions