3 ms·
Depends on the language I guess. For me this is easier to read (and reason with) in JS: const y = (i <== 1 && i < a.length()) ? a[i] : -Huge(i); than:
by skywal_l 5y ago
Depends on the language I guess. For me this is easier to read (and reason with) in JS:
const y = (i <== 1 && i < a.length()) ? a[i] : -Huge(i);
than:
let y; // What do I initialize this too.
if (i <== 1 && i < a.length()) {
y = a[i]; // a side effect
} else {
y = -Huge(i); // another side effect
}
And you end up with a mutable variable that might change later on (true only for language with mutable/non mutable variable of course).
Besides, it blends well with functional programming where side effect are better avoided.
- Someone 5y agoAlso depends on what you assign to. If you read an if/else statement, you have to check whether both branches assign to the same value. If that’s a complex expression, that isn’t trivial.
- pklausler 5y agoFortran’s ASSOCIATE construct can help with that. associate (x=>(complicated variable)) if (test) then x = … else x = … end if end associate
- veltas 5y agoYou have cheated by adding that comment noise.