develooper Front page | perl.perl5.porters | Postings from December 2010

Re: [perl #80628] [PATCH] __SUB__

Thread Previous | Thread Next
From:
Abigail
Date:
December 13, 2010 05:04
Subject:
Re: [perl #80628] [PATCH] __SUB__
Message ID:
20101213130419.GE29007@almanda
On Mon, Dec 13, 2010 at 01:38:02PM +0100, demerphq wrote:
> On 13 December 2010 13:04, Abigail <abigail@abigail.be> wrote:
> > On Mon, Dec 13, 2010 at 12:33:24PM +0100, demerphq wrote:
> >> On 13 December 2010 11:42, Abigail <abigail@abigail.be> wrote:
> >> > On Mon, Dec 13, 2010 at 11:32:45AM +0100, Johan Vromans wrote:
> >> >> [Quoting demerphq, on December 13 2010, 10:48, in "Re: [perl #80628] [P"]
> >> >> > This is why i proposed using a $^THIS_SUB "magic tied var" for the purpose.
> >> >>
> >> >> Sounds like a very good idea to me.
> >> >>
> >> >> My main objection against __SUB__ is that __XXX__ things are currently
> >> >> compile time constants, hence we must avoid introducing __XXX__ things
> >> >> that are not. It doesn't contribute to Perl's popularity.
> >> >
> >> >
> >> > I wouldn't say __END__ and __DATA__ (probably the most well-known, and
> >> > certainly the most used __XXX__ thingies) are "compile-time constants".
> >> >
> >> > So, I don't really buy the "__SUB__ confuses me, because it isn't a
> >> > compile-time constant" argument.
> >> >
> >> > __XXX__ things I know about, in order how often I see it used in code:
> >> >
> >> > __END__:   Special token
> >> > __DATA__:  Special token
> >> > __WARN__:  Special literal for %SIG
> >> > __DIE__:   Special literal for %SIG
> >> >
> >> > <huge gap>

I forgot one  here:

       __PACKAGE__: Compile-time constant

> >> >
> >> > __FILE__:  Compile-time constant
> >> > __LINE__:  Compile-time constant
> >> >
> >> >
> >> > Now, I'd prefer a short token, and I certainly don't mind having a variable,
> >> > so $^SUB now wins for me. But __SUB__ doesn't shout "compile-time constant"
> >> > to me. (What constant should it possibly be?)
> >>
> >> I think johan meant it in the sense that you dont expect to be able to
> >> localize, or assign to an __IDENTIFIER__, which fits the use case for
> >> this feature.
> >>
> >
> >
> > Good point.
> >
> > But that, IMO, would favour __SUB__ over $^SUB. The latter may give the
> > suggestion you can assign to it, or localize, while "the current sub"
> > isn't something I associate with as assignable from Perl land.
> 
> Yes right. I'm happy with FC's patch, and would like to see it go in.
> 
> The only that might be odd with it is that it would return a ref, and
> the other things return simple scalar values.


Yes, but people do write "__PACKAGE__ -> ... ()" without being freaked
out. "__SUB__ -> ()" isn't visually that much different, even if one
returns a string, the other a code ref. For a typical use, the user
does not have to care.


Abigail

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