This is a form of thought that seems to have evolved over time.
I remember when I started programming the de facto standard was one-entry, one-exit. And that is still being taught in many OO courses in universities.
However, there are many schools of thoughts (including more recently mine) that come down on the side that a moderate number of return statements can actually enhance code readability.
For example, compare this:
1 2 3 4 5 6 7 8 9 10 11 12 |
double getPayAmount() { double result; if (_isDead) result = deadAmount(); else { if (_isSeparated) result = separatedAmount(); else { if (_isRetired) result = retiredAmount(); else result = normalPayAmount(); }; } return result; }; |
versus this:
1 2 3 4 5 6 |
double getPayAmount() { if (_isDead) return deadAmount(); if (_isSeparated) return separatedAmount(); if (_isRetired) return retiredAmount(); return normalPayAmount(); }; |
which uses guard clauses [Beck] / [Fowler’s Refactoring].
http://sourcemaking.com/refactoring/replace-nested-conditional-with-guard-clauses
and
and