Coding Standards / Coding Best practices in C++

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

    I've used similar to both in different circumstances but you've overcomplicated the first IMO:

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

提交回复
热议问题