develooper Front page | perl.perl5.porters | Postings from April 2012

Re: [perl #24250] "return" required in some anonymous closures

From:
Nicholas Clark
Date:
April 21, 2012 03:45
Subject:
Re: [perl #24250] "return" required in some anonymous closures
Message ID:
20120421104515.GD9069@plum.flirble.org
On Sat, Apr 21, 2012 at 10:48:13AM +0200, demerphq wrote:
> On Friday, 20 April 2012, Dave Mitchell wrote:
> 
> > On Fri, Apr 20, 2012 at 12:37:55PM +0100, Nicholas Clark wrote:
> > So, I think we should remove this 'feature'.
> > If anyone is using it as intended, then the worst they'll get is
> > a performance decrease, with a const sub downgraded to a real sub that
> > returns the expected value. Perhaps we could issue a warning, with
> > perldiag.pod explaining what to do if you really wanted a const sub, and
> > to stick a 'return' in to defeat the warning if you didn't want it.
> >
> 
> We use this a lot at work. We can recode to use other mechanisms to produce
> constants, tho, so it's not a big deal, but my suspicion is its widely
> used. Keep in mind that constants can be used to modify the optree and are
> used for that as much as a value.
> 
> Dosomething() if CONSTANT;
> 
> Is used a lot.

Not sure if you're aware as it's been cut - the context is *specifically*
constants of the form:

    sub CONSTANT_FROM_VAR () { $foo; }

constants generated like this:

    sub CONSTANT_FROM_CONSTANT () { 42 }

aren't a problem.

(And constants generated by constant.pm aren't a problem)

Nicholas Clark



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