develooper Front page | perl.perl5.porters | Postings from June 2008

Re: [perl #56150] return return

Thread Previous | Thread Next
From:
H.Merijn Brand
Date:
June 23, 2008 07:06
Subject:
Re: [perl #56150] return return
Message ID:
20080623160547.78a3399b@pc09.procura.nl
On Mon, 23 Jun 2008 09:52:00 -0400, Mark Mielke <mark@mark.mielke.cc>
wrote:

> First, it should be understood by all that this question is really about 
> STYLE - not about universal readability. There are different answers, 
> and there are different opinions. People who come from a LISP background 
> may find it easier to read one style than people from a C background. 
> Therefore, for anybody to claim that one is universally easier to read 
> than another is FALSE. It can only be easier to read for a section of 
> the population. As to which section of the population is bigger? ...
> 
> Aristotle Pagaltzis wrote:
> > * Mark Mielke <mark@mark.mielke.cc> [2008-06-23 01:10]:
> >   
> >> If your suggestion is that "return" improves readability, I
> >> disagree that the addition of "return" will universally improve
> >> the ability for a person to read the code.
> >>     
> >
> > As long as you have the discipline to always, *always* write a
> > bare `return;` in functions that are meant not to return a value,
> > and the maintenance programmer who comes after knows of your
> > discipline in that matter, then using `return` when you do mean
> > to return a value is not necessary.
> >   
> 
> There are alternatives. For example, most people end their modules with 
> "1;" effectively saying "return 1;". In my case, I have had functions 
> such as you describe with:
> 
> sub NAME
> {
>     ... lots of code ...
> 
>     undef;
> }

What if the function can return a list or a scalar? "return" handles
that automatically, undef does not;

BTW I agree with both worlds. In some cases it should suffice to use
the last value, in some cases one should use return for clarity

-- 
H.Merijn Brand          Amsterdam Perl Mongers  http://amsterdam.pm.org/
using & porting perl 5.6.2, 5.8.x, 5.10.x, 5.11.x on HP-UX 10.20, 11.00,
11.11, 11.23, and 11.31, SuSE 10.1, 10.2, and 10.3, AIX 5.2, and Cygwin.
http://mirrors.develooper.com/hpux/           http://www.test-smoke.org/
http://qa.perl.org      http://www.goldmark.org/jeff/stupid-disclaimers/

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About