I have a long(ish) function of the following pattern:
bool func(some_type_t *p1, another_t *p2)
{
bool a = false, b = false, c = false, etc = false;
a = (some_long && expression && \
(that_deserves | its_own_line));
b = (another || long_expression && \
(that_deserves | its_own_line));
c = and_so && on;
return a && b && c && etc;
}
As you can see, the return value is true
if and only if all flags are true. Hence I can return as soon as one of them turns out to be false
. It may or may not be more optimal than the current version, but I want to do it to satisfy my OCPD. I thought of putting everything in a do{}while(0);
and breaking out on false
, but that looks odd (and I remember seeing something like that in tdwtf).
I do not want multiple return statements or deeply nested if blocks, and I certainly don't want to compromise on readability with a huge if that relies on short circuiting. I can live with goto
in this case, but I want to know if there are any other patterns/constructs used in similar scenarios.