4 ms·
how do people currently write conditional statements?
by steviedotboston 5y ago
how do people currently write conditional statements?
- Bostonian 5y agoThe current equivalent to the one-liner I presented is if (i>=1 .And. i<=Size(a)) then y = a(i) else y = -Huge(y) end if
- walshemj 5y agoThis to me looks more readable than a one liner
- skywal_l 5y agoDepends 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.
- renewiltord 5y agoThe word of greatest value in the headline is “expressions”. There are conditionals in FORTRAN but now you can have a conditional that evaluates to something.