Coding Standards / Coding Best practices in C++

前端 未结 17 1629
醉话见心
醉话见心 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:18

    My habit is to avoid if-blocks this way:

    bool MyApplication::ReportGenerator::GenerateReport(){
        bool report = !( isAdmin()        || isConditionOne() || 
                         isConditionTwo() || isConditionThree() );
        return report ? generateReport() : false; 
    }
    

提交回复
热议问题