2 ms·
There are ways to flatten those trees and leave the code a bit more readable. Bertrand Meyer hit on it 30 years ago: if (weShouldDoThis()) { return d
by hinkley 6y ago
There are ways to flatten those trees and leave the code a bit more readable. Bertrand Meyer hit on it 30 years ago:
if (weShouldDoThis()) {
return doIt();
}
Structurally, this seems very similar to having twenty methods with one conditional block and a delegation to some other method. But the stack trace is half as high, and the testing surface area is greatly improved, because the code in the 'if' clause is pure, or close to it, while the 'doIt()' method might alter shared state.
There's a big difference from a robustness standpoint between having half of your functions pure, and half of each function pure.