|
From: Jonathan S. <gel...@ge...> - 2002-02-22 22:27:37
|
On Fri, 22 Feb 2002, Chris Devers wrote: > On Fri, 22 Feb 2002, Alex BATKO wrote: > > 05) Poor programming technique: multiple return points in one subroutine. > > A subroutine should be written in such a way that there is only one > > return statement (and it is the last statement of the subroutine). > > In this respect the do_search subroutine is a really great example > > of this poor technique. > > Ok this I totally reject. I don't see the benefit of adding in all the > necessary plumbing to force all functions to have one 'in' and one 'out'. > If you encounter a termination condition at the top of the function, you > shouldn't be forced to go to the bottom of that function just to escape. > In this I place a higher precedence on "goto considered harmful" than > "multiple exits considered harmful". > > Why is this considered to be such a great design criteria, anyway? When I > was first learning to progam in C++, being forced to do this was a great > source of bugs for me, and it didn't really make anything I wrote all that > much clearer in the first place. No one told us that we could just escape > out of a function, avoid all that buggy scaffolding code that's needed to > support single-exit, *and* make execution flow IMO much clearer. > > Unless you can offer a pretty good justification for this, I don't see any > reason to rewrite everything so that it adheres to this rule. > Yeah, if you speak up on this list with a suggestion you had better be prepared to implement it ;-} Earlier in my career I worked with a lot of COBOL programmers and they would have been of a similar position to Alex - I *can* program COBOL if pressed but I would never describe myself as a COBOL programmer :) But this is fine: you simply collected all the failures and have one exit point with the appropriate exit code. I'm not sure that the body of Perl thought will go along with this but if you think that this is where you want to go feel free to implement it :) /J\ -- Jonathan Stowe | <http://www.gellyfish.com> | This space for rent | |