develooper Front page | perl.perl5.porters | Postings from November 2011

Re: RFC: Autoloading charnames

Thread Previous | Thread Next
From:
Karl Williamson
Date:
November 22, 2011 15:03
Subject:
Re: RFC: Autoloading charnames
Message ID:
4ECC2A1E.9040401@khwilliamson.com
On 11/22/2011 03:23 PM, Jesse Luehrs wrote:
> On Tue, Nov 22, 2011 at 05:17:41PM -0500, David Golden wrote:
>> On Tue, Nov 22, 2011 at 5:03 PM, Karl Williamson
>> <public@khwilliamson.com>  wrote:
>>> It has been proposed that charnames automatically load when a \N{} is seen.
>>>   That is easy to do, and I think it should load as if the :full and :short
>>> options had both been specified.
>>>
>>> Does anyone disagree with doing this?
>>
>> What are the pros and cons, specifically, of choosing either or both
>> of :full and :short?  Would it be loaded at compile time or runtime?

\N{} is compile time, so this would be as well.  The reason to choose 
:full is that is what people generally expect.  The universe of names 
matched by it and :short is disjoint, as :short name matches require a 
colon in them, and :full name matches forbid a colon.  e.g., 
\N{greek:alpha} is matched by :short.  I don't see any cons of having 
both :full and :short be accepted.  The pro of having :short auto loaded 
is that it just happens without you having to worry about it.  There's 
no extra memory, etc. required to have it.

I had considered having :loose instead of :full, which is an extension 
of :full allowing more sloppy name input that meets the Unicode 
standard's recommendations.  However, Perl traditionally has only had 
:full, and I thought it could cause confusion, besides being slower.

>>
>>> If it is done, should the functions in the module also autoload.  That is,
>>> should a line like 'my $poo = charnames::viacode(0x1F4A9)' fail if charnames
>>> hasn't been 'used' or 'required' or should it cause the module to load ?
>>
>> I don't like general-purpose auto-loading.  However, I can see the
>> case for \N{} (just I saw the case for autoloading IO::File when
>> methods are called on filehandles.  If \N{} does load charnames, then
>> I would expect charnames::viacode(...) to work.  However, without
>> prior \N{} (assuming compile-time loading), I would expect
>> charnames::viacode() to be a compilation error.
>
> I personally wouldn't expect the presence or absence of a \N{} escape at
> some arbitrary location in my code (possibly even in a different file)
> to make the difference (on its own) of whether calling functions in
> charnames:: worked or not. This seems like it would cause confusion.

This was a concern of mine as well.  Since subroutines are global, if 
anyone loads the module, they get defined everywhere, unless I'm missing 
something.

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