如何改进if算法


How to Improve if algorithm

如何做得更好?不重复代码someFunction(1)。

        if(someTrueOrFalse)
        {
                if(OthersomeTrueOrFalse)
                {
                    someFunction(1);
                }
        } 
        else
        {
            someFunction(1);
        }

A=someTrueOrFalse和B=OthersomeTrueOrFalse

 A | B | outcome
-----------------
 0 | 0 |    1
 0 | 1 |    1
 1 | 0 |    0
 1 | 1 |    1

因此:

if (!(someTrueOrFalse && !OthersomeTrueOrFalse)) {
    someFunction(1);
}

或者,相当于@axiac 的评论

if (!someTrueOrFalse || OthersomeTrueOrFalse) {
    someFunction(1);
}

我想,这取决于情况,两者中哪一个看起来更好(或者有时只是品味问题)。