Boolean types

前端 未结 10 2104
时光说笑
时光说笑 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:37

    Yes, you should do it as you say. These people are doing these overly verbose things because they first learned it that way, perhaps in CS 101, and it never occurs to them to go outside the space of what they know works to see if there is a better, easier way.

    This does speak to their competence. Good programmers need to be a little more thoughtful and a lot less hidebound.

提交回复
热议问题