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

Re: [perl #56150] return return

Thread Previous | Thread Next
From:
Tels
Date:
June 20, 2008 14:01
Subject:
Re: [perl #56150] return return
Message ID:
200806202202.36880@bloodgate.com
On Friday 20 June 2008 21:20:54 David Nicol wrote:
> On 6/20/08, Yitzchak Scott-Thoennes <sthoenna@efn.org> wrote:
> >  > general "code unreachable" warning
> >
> >  which return(return) would trigger but return($x || return) would
> > not
>
> but
>
>    my $x=0;  return($x || return)
>
> would, if we can apply used-as-lvalue analysis to constant folding
>
> (ivory-tower to the point of being off-topic)

Why not add rules to Perl::Critic to catch these? 

Also, I'd like to add that "return" at the end of a function is almost 
always pointless, too. "$x" works just as fine as "return $x" and is 
potential faster:

	$ perl -MO=Concise -wle 'return 1;'
	6  <@> leave[1 ref] vKP/REFC ->(end)
	1     <0> enter ->2
	2     <;> nextstate(main 1 -e:1) v ->3
	5     <@> return K ->6
	3        <0> pushmark s ->4
	4        <$> const[IV 1] s ->5
	-e syntax OK
	$ perl -MO=Concise -wle '1;'
	3  <@> leave[1 ref] vKP/REFC ->(end)
	1     <0> enter ->2
	2     <;> nextstate(main 1 -e:1) v ->3
	-     <0> ex-const v ->3
	-e syntax OK

The only thing that speaks for return is that it "speaks" e.g. looks 
more nice to the human reader.

All the best,

Tels

-- 
 Signed on Fri Jun 20 21:57:22 2008 with key 0x93B84C15.
 Get one of my photo posters: http://bloodgate.com/posters
 PGP key on http://bloodgate.com/tels.asc or per email.

 "Sundials don't work, the one I've had in my basement hasn't changed
 time since I installed it." grub (11606) on 2004-12-03 on /.


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