> From: Thomas Singer <[EMAIL PROTECTED]>
> Subject: RE: [Eap-list] Extract Method with multiple exit points
>
> >1. When extracting method which contains a "continue" statement and
> >returns "void" - change the continue to return (it shouldn't work if
> >the statement is "continue <label>").
>
> And what, if the piece of code contains a "break" or both, a "break"
AND a
> "continue"?
Then the method could have an artificial boolean return value which
would indicate break.
Again it's ugly, but gives you chance to refactor it into something
better. Moreover this way
you give a name to the break condition.
Example:
this:
...........................
synchronized (rec) {
LOGGER.debug("waiting on " + rec.symbol());
long endTime = System.currentTimeMillis() + timeout;
while (!rec.hasData()){
if (endTime < System.currentTimeMillis()) {
LOGGER.warn("Timeout while waithing for "+rec.symbol()+"
Proceeding with next.");
break;
}
if (!rec.active()){
LOGGER.debug("Record "+rec.symbol()+" inactive.
Proceeding with next.");
break;
}
try {
rec.wait(timeout);
} catch (InterruptedException ex) {
LOGGER.debug(ex.toString());
}
}
}
...........................
could become:
...........................
synchronized (rec) {
LOGGER.debug("waiting on " + rec.symbol());
long endTime = System.currentTimeMillis() + timeout;
while (!rec.hasData()){
if (!checkInvariantsWaitUpdate()) break;
try {
rec.wait(timeout);
} catch (InterruptedException ex) {
LOGGER.debug(ex.toString());
}
}
}
...........................
I find the latter more readable and it gives me the posibility to reuse
the checkInvariants method. (Yes I did it.)
regards
dimiter
_______________________________________________
Eap-list mailing list
[EMAIL PROTECTED]
http://www.intellij.com/mailman/listinfo/eap-list