Welcome to the Monastery | |
PerlMonks |
Re: Control Flow - Multiple returns or nested conditionalsby jethro (Monsignor) |
on Oct 07, 2010 at 16:20 UTC ( [id://864032]=note: print w/replies, xml ) | Need Help?? |
Not using multiple returns is one of those old rules that emerged out of the 'Goto considered harmful' war, I think. Still the goal to reach is always to have the most readable and maintainable code. The danger of multiple returns is that maintaining it can be difficult. So if that danger is more than compensated by a clearer structure of the sub, it is acceptable IMHO. I can think of two general types of subroutine where that is often the case: 1) When the logic of a subroutine has many exceptions or error conditions. 2) The "big switch" subroutine, i.e. the subroutine with a long switch/case statement When I use multiple returns in a subroutine, I always mention it prominently in the comments at the head of the sub. Whether your example is already exceptional enough for multiple returns is a matter of taste. I think I wouldn't have used them there, but I might have given a different answer yesterday ;-).
In Section
Seekers of Perl Wisdom
|
|