Post

Probably a spicy take but I think variable scope clarity in programming languages could be improved. bool flag = false; if (foo) { ...many lines... flag=true; } ...many lines... if (flag) { Really, flag just needs to exist in both of those blocks, no the parent block.

0 reposts0 likes

Said another way: Currently, the only way to share a variable between two blocks is to put that variable in a shared parent block. Even if the parent doesn't care and the other blocks/code don't care. It feels like there has to be a better way.

Feels like a cousin of the capture clause with Lambdas? Like you could have a capture before a block that says "preserve block internal variables XYZ and make them available as parameters to sibling blocks aliased as ABC"? And also those blocks could be thought of as one-shot lambdas.