|
|
|
|
|
by tpoacher
1894 days ago
|
|
I agree, but also I think this is misrepresenting the 'early return' pattern. It's more likely to be succinct and look like this instead: function check(x) {
if (!test1 (x)) return false;
if (!test2 (x)) return false;
if (!test3 (x)) return false;
if (!test4 (x)) return false;
return true;
}
In _this_ scenario, it is true that this is much more readable than: function check(x) {
if (!test1 (x)) {
return false;
} else if (!test2 (x)) {
return false;
} else if (!test3 (x)) {
return false;
} else if (!test4 (x)) {
return false;
} else {
return true;
}
}
|
|
Your first example would still look clean like this:
And it would be much safer from stupid copy/paste errors.