lundi 4 mai 2015

Chain of OR conditions in if statement

In my code I have a if statement, which looks like:

if(someFunction1(a) || someFunction2(b->b1,c) || *d == null || somefunction3(e) > f * g || !e->e1 || ...){
   return 0;
} else {
   do_something;
}

In my code with real variable and function names are conditions nearly in three lines and it looks very overlook. So I decided to rewrite it into form:

if(someFunction1(a)){
   return 0;
} else if(someFunction2(b->b1,c)){
   return 0;
} else if(*d == null){
   return 0;
} else if(somefunction3(e) > f * g){
   return 0;
} else if(!e->e1){
   return 0;
} else if(...){
   return 0;
} else{
   do_something;
}

Is there any argument why I should not do it?

Aucun commentaire:

Enregistrer un commentaire