我有一个很长的条件如下。有两个条件不能满足,要评估的陈述。我确实把它作为一个有很多& &和!但它变得不可读。我试图将其拆分成if elsif else
,它更易读,但读取不好,因为第一个if elsif
块中没有代码。编码风格 - 我如何格式化一长条件,使其可读
整理此代码块的最佳做法是什么?
if ($instructionObject->instruction=='nesting_grammar' && $instructionObject->match=='>'){ //if instruction is a '>' child indicator
//don't change the child depth
}else if ($instructionObject->instruction=='selector' && is_object($this->instructions[$key+1]) && $this->instructions[$key+1]->instruction == 'nesting_grammar' && $this->instructions[$key+1]->match == '>'){ //if instruction is a selector followed by a '>'
//don't change the child depth
}else{
$insertOffset += $childDepth;
unset($childDepth);
}
我给了这个+1,但我越想越多,我意识到这只是将臃肿的'if'条件移动到文件的另一部分。它看起来不错,但现在来自未来的程序员必须找到函数声明来找出发生了什么。嗯... – keyboardSmasher