Re:Anti-if: The Missing Patterns
by michaelmior on Thursday June 09, 2016 @11:59PM
(#11874204)
One thing I've always done with if statements is when I have an if with a negated condition and no else case
When I want to add an else case, I swap the order so the condition is no longer negated.
To me it's easier to read a non-negated condition and the else case then feels more natural. (It avoids having to internally think about else case as "condition not not satisfied".)
[ Parent
| on HN ]
Interesting. I often (but not always) prefer the if (!condition) {} at the top because I see it as 'bailing out' of the function if conditions are not met.
Re:Anti-if: The Missing Patterns
by michaelmior on Sunday June 12, 2016 @04:10PM
(#11890002)
If I'm doing an early return, I usually don't put the rest of the function inside the else case since I feel it creates an unnecessary level of indentation.