【发布时间】:2010-09-02 18:48:27
【问题描述】:
我刚刚和一位同事讨论过,我们不同意以下哪个 sn-ps 更简单:
public boolean foo(int x, int y) {
if (x < 0)
return false;
if (y < 0)
return false;
// more stuff below
}
或
public boolean foo(int x, int y) {
if (x < 0 || y < 0)
return false;
// more stuff below
}
哪个更短很明显;很明显,它们的cyclomatic complexity 是相同的(因此对于“简单”的定义,它们当然是相同的)。
你的感受是什么,为什么?哪个更具可读性;哪个更容易调试?
【问题讨论】:
标签: language-agnostic coding-style