4 ms·
Personally, I prefer to just split long if statements into multiple lines. if ( (_someLongNamedVar != FooLongNameEnum::Unknown) && (_someLo
by bakugo 4y ago
Personally, I prefer to just split long if statements into multiple lines.
if (
(_someLongNamedVar != FooLongNameEnum::Unknown) &&
(_someLongNamedMap.count(_someLongNamedVar) == 0)
) {
// do something
}
- seydor 4y agoright, but putting the && at the beginning of the next line makes it more obvious this is a continuation statement
- heleninboodler 4y agoI actually like putting the && on its own line in between.
- rzzzt 4y agoFor bonus alignment points and malleability, start with 'true' and place the closing parenthesis on a new line: if (true && condition1 && condition2 && condition3 ) { ... } If you ever need to change the set of conditions, the diff will cleanly add/remove whole lines.
- masklinn 4y agoOr borrow a page from the FP language folks, which gets most of the way there (prepending an items is still a -1+2 diff) without the weird initial clause: if ( condition1 && condition2 && condition3 ) { ... } Obviously the best alternative is to switch to a prefix language and sidestep the issue entirely: (when (and (condition1) (condition2) (condition3)) ...)