Boolean types

前端 未结 10 2123
时光说笑
时光说笑 2021-01-22 11:54

During code review I discovered many places of our C# code that looks like this:

if(IsValid()) {
     return true;
}
else {
     return false;
}
<
10条回答
  •  感动是毒
    2021-01-22 12:35

    Distraction

    I know it's occurred in my code before and I can trace that back to when I was interrupted or not paying attention while coding (I solely blame SO!)

    Ignorance

    Not knowing the better way to do it. We take it for granted that all programmers think logically, but that's not the case. Some coders are going purely on patterns of what they've seen before:

    If (integerA == integerB) { //do special stuff }
    
    //Given integer equality; boolean equality ought to look the same...
    If (isValid() == true ) { //do special stuff }
    

    Momentum

    That's how someone has always done it and therefore that's how they continue to do it.

提交回复
热议问题