4 ms·
You may not want a fresh scope for control flow as you often want to use variables from the outer scope inside the if statement. Imagine you wanted to do someth
by andriamanitra 1y ago
You may not want a fresh scope for control flow as you often want to use variables from the outer scope inside the if statement. Imagine you wanted to do something like this with your if statement implemented with a function (this is how the syntax would look like using a block argument in Ruby):
state = "inactive"
if_func(condition) {
state = "active"
activate_button.disabled = true
deactivate_button.disabled = false
}
In many languages you would need to wrap `state` in something that can be passed by reference, and make the function take multiple parameters. For example in JavaScript it would turn into something like this mess:
let state = ["inactive"];
if_func(condition, ({state, activate_button, deactivate_button}) => {
state[0] = "active";
activate_button.disabled = true;
deactivate_button.disabled = false;
}, {state, activate_button, deactivate_button});
- 8n4vidtmkvmk 1y agoI think that part could use some improvement. References vs values should have different syntax, like C++. I think the interpreted languages and Java botched this.