At 11:28 12.07.2001 -0400, Kurt Edmiston wrote:
>Here's a topic for discussion:
>
>Coming from C++-land, I've always been taught over and over again that all 
>subroutines/functions/blocks/etc should have only a single entry point and 
>a single exit point.  "It's just good programming practice."  But now in 
>the world of Perl, I've observed that a "Perl-ish" thing to do is to place 
>multiple return/exit/etc statements in certain blocks of code or in 
>conditional blocks.  (Then again, maybe it isn't Perl-ish, but I've had to 
>sort through many perl scripts like this.)
>
>I guess I'm just curious to know what other more experienced Perl 
>programmers think about this.  I still adhere strictly to the "one way in, 
>one way out" philosophy, mainly for the sake of readability.  But I 
>understand how much easier it can make a programmer's task to write 
>something like "if (some condition) { exit; }"
>
>Also, I was wondering if exiting prematurely like this from a program has 
>any adverse affects on the execution of the program.
>
>Thanks,
>Kurt
>

This is an interesting discussion topic,

I do C++ myself, and have no qualms about exiting early if I run into a 
problem -- either by returning an error code, or exiting the program 
altogether, if the error is something I can't recover from -- in Perl, C++, 
JavaScript, or any other language I happen to be writing in.

I've seen a lot of code with 10's of embedded blocks, all with conditions 
that guide the flow to a final destination -- it's so ugly!  What's wrong 
with putting all of your error checking at the top of your function, and 
then jumping out if you run into something you don't like.  It makes the 
meat of the function easier to read.
Aaron Craig
Programming
iSoftitler.com

Reply via email to