java - How to refactor a step-wise code? -
consider code sample.
is pattern not aware of ?
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
Post a Comment