This came up today in a code review and I'm seriously wondering other people's
opinions.
Basically the code was this (inside a function):
if (a && (b || c || d)) {
// Some statements here
}
And the reviewer said: Consider changing that
if to return early so that wecan reduce indentation making the code more readable.
Fair enough, let's apply DeMorgan:
if (!a || (!b && !c && !d)) {
return;
}
// Some statements here
I myself like a lot better the first version since it deals with positive
logic which is a lot clearer for me, I can read that as a sentence and
understand it completely while the second version I need to stop for a minute to
reason about all those negations!
https://redd.it/1oibqxa
@r_cpp