if (x() > 10) { if (y > 5) action1(p1, p2, p3, p4); else action2(p1, p2); } else { if (z > 2) action1(p1, p2, p3, p4); else action2(p1, p2); }
I real project on mine, action1 and action2 are actually 2-3 lines of code and those functions that are invoked take 6-8 parameters in total, so writing them as a single function doesn’t seem right.
UPDATE: I forgot to mention this, and now I see many answers just don’t work. x() is expensive operation and has side-effects, so it should not be called twice.
Or, alternatively, what Roger Lipscombe answered.