java - How to refactor a step-wise code? -


consider code sample.

  1. is pattern not aware of ?

  2. how clean clutter ?

    int func1val = func1(); boolean val = checkiftrue(func1val); if (val) {     int func2val = func2();     val = checkiftrue(func2val);     if (val) {         int func3val = func3();         val = checkiftrue(func3val);     } }  if (val) { // print func1val, func2val, func3val,  }  

it looks you're printing out 3 values if , if checkiftrue returns true three. barring implementation detail of checkiftrue, couldn't like

int func1val = 0, func2val = 0, func3val = 0; // value here if (checkiftrue(func1val = func1()) && checkiftrue(func2val = func2()) && checkiftrue(func3val = func3())) {     // print func1val, func2val, func3val } 

to fair, like

int func1val = func1(); if (checkiftrue(func1val)) {     int func2val = func2();     if (checkiftrue(func2val)) {         int func3val = func3();         if (checkiftrue(func3val)) {             // print func1val, func2val, func3val         }     } } 

ought same thing, , may more readable depending on actual situation.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -