Coding Standards / Coding Best practices in C++

前端 未结 17 1778
醉话见心
醉话见心 2021-01-02 09:06

Consider the two code segments below. Which one is better and Why? If you have any other idea, please do mention. Where can I find answers to coding p

17条回答
  •  醉酒成梦
    2021-01-02 09:14

    Which on do you think best expresses what the code is trying to say. Which one do you need to work hardest to understand?

    I would do this:

    bool MyApplication::ReportGenerator::GenerateReport(){
        if (isAdmin()  && isConditionOne() && isConditionTwo() && isConditionThree()){
             return generateReport();
        } else {
            return false;
        }
    
    }
    

    Because:

    a). Prefer to say what I want rather than what I don't want b). prefer symmetry, if and else. Clearly all cases covered.

提交回复
热议问题