4 ms·
Can confirm. Made this mistake myself actually. However to make a contradictory point apart from being better style what are the other advantages of not using i
by thecleaner 7y ago
Can confirm. Made this mistake myself actually. However to make a contradictory point apart from being better style what are the other advantages of not using if statements and use boolean algebra instead ?
- munchbunny 7y agoVerbosity tends to hurt readability, but trying to cram too much into one line tends to create something where nobody remembers how it works either. So it's really a judgement call on which approach reads more naturally. My personal rule of thumb on this is that single statement conditions aka "a = {condition}" should be using only "and" operators or only "or" operators and should generally avoid nesting unless there's a clear explanatory comment. So "a and b and c and d" is ok but "a and b or c and d" is sketchy. The reason is that "all" and "any" are idiomatic, but "some" takes more mental work to parse. Also it's always useful to keep in the back of your mind: !(a || b) == !a && !b Whenever I spot either side of the equation in a condition, I stop and consider whether the alternate formulation would be more readable.