3 ms·
I think it depends on what you're trying to do. Is the expression a fundamental business rule? Then splitting it up runs the risk of introducing error/inconsist
by majormajor 8y ago
I think it depends on what you're trying to do. Is the expression a fundamental business rule? Then splitting it up runs the risk of introducing error/inconsistency, I think.
But if you're just trying to condense down separate business rules, where it happens that today that you want the same thing in the case of `baz` as for `(foo && bar)`, then you're setting yourself up for a more painful change when someone comes to you and says "hey actually let's have `baz` do the other thing after all. Yeah, in the trivial case where it's just returning bools, that's not really an issue, but when I see code that looks like the former it's usually more complicated, and the overlap is more often incidental rather than fundamental.
So my approach is more "remove nested ifs" than "simplify it into as few cases as possible."