3 ms·
Short circuiting is poor for readability in my view because not only do you have to parse the syntax but you need to mentally walk through each case to understa
by spectramax 7y ago
Short circuiting is poor for readability in my view because not only do you have to parse the syntax but you need to mentally walk through each case to understand what’s going on.
Traditional if/else conditionals express clarity by embedding the decision for myVar and visually show how it would be assigned in various cases.
As @hotBacteria said:
if(cond1){
myVar = 1;
} else if(cond2 && cond3){
myVar = 10;
} else if(cond2 && !cond3){
myVar = 100;
} else {
myVar = 4;
}
// Now return myVar
return myVar;
I’ll take this syntax over short circuiting any day.
- drawkbox 7y agoClear conditionals like this (or short circuiting) are very nice when it comes to merging. One liners and mammoth tertiaries that are too long can lead to conflicts and more problematic merges/diffs/etc. One operation per line makes repos and merging, as well as blaming, reading and reviewing, easier to parse.