In Clean Code, Robert Martin writes, “Negatives are just a bit harder to understand than positives. So, when possible, conditionals should be expressed as positives.” (Martin, [G29]). IntelliJ IDEA has three inspections to help you stay positive.
在洁净代码中马丁.罗伯特写到:负值比正值难以理解一点。因此,如果可能,尽量使用正值的表达式。IntelliJ IDEA有三项检查帮助你保留正值。
for example:
boolean isBigger(a,b){
return a >b;
}
boolean isLess(a,b){
return a <=b;
}
if(!isBigger(c,d)){//1
System.out.println(c+"is less than " +d);
}
if(isLess(c,d)){//2
System.out.println(c+"is less than " +d);
}
2 是比较好理解的代码,1是比较难以理解的代码。
网友评论