Robert Klemme
1/31/2008 5:06:00 PM
On 30.01.2008 20:27, Phlip wrote:
> There's a reason professors of BDUF techniques used to say a routine
> should have a single entry and a single exit. The reason is not the exit
> count itself. Applying the rule forces you to examine and clean up your
> control flow, between that entry and exit.
I am not a big fan of that rule. Multiple exits can come in handy, for
example when doing this:
# superfluous in Ruby of course
def find(enum, x)
enum.each do |elm|
return elm if x == elm
end
nil
end
Avoiding multiple exits can lead to increased indentation because you
might need more control constructs.
Especially in programming languages with exceptions the "single exit"
rule is pretty useless - unless you do not count exceptions.
Kind regards
robert