jeudi 11 janvier 2018

Is it possible to combine an else with the rest the scope in C/C++

So lets take this code:

{
    if(b){
        return f();
    }else{
        a = fa();
        fun(a);
        return funb(a);
    }

    a = fa();
    return funb(a);
}

The problem here for me is, this code is not very clean and simply looks ugly. That´s why I changed it to this:

{
    if(b){
        return f();
    }
    a = fa();

    if(!b){
        fun(a);
    }

    return funb(a);
}

But the problem here is the double check of boolean b, which is not a function, but simply a boolean variable (so not calculation necessary).

My question is how can I improve this code to make it clean, DRY and don´t double check the boolean. This code is performance critical and thus this if does make a difference.

Aucun commentaire:

Enregistrer un commentaire