Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

RFC: Export tags for builtin pragma

by kcott (Archbishop)
on Oct 19, 2023 at 17:42 UTC ( [id://11155064]=perlmeditation: print w/replies, xml ) Need Help??

G'day All,

I'm intending to propose export tags for the builtin pragma. I'd appreciate any comments you may have about this. Thankyou.

A Brief History of the 'builtin' Pragma

My Usage of the 'builtin' Pragma

When released, I often play around with experimental features; however, I never use them in production-grade code. I did the same with the builtin pragma and found many to be useful: in some cases, I also found the import lists to be quite unwieldy.

When Perl v5.40.0 is released, presumably sometime next year, I will probably start using many of the stable functions provided by the builtin pragma in production-grade code. I would like easier to use import lists; accordingly, I'm proposing a number of export tags.

Proposed Export Tags for the 'builtin' Pragma

:bool
Exports: true, false, is_bool.
:weak
Exports: weaken, unweaken, is_weak.
:ref
Exports: blessed, refaddr, reftype.
:round
Exports: ceil, floor.
:stable
Exports all stable (i.e. non-experimental) functions.
:all
Exports all functions.

— Ken

Replies are listed 'Best First'.
Re: RFC: Export tags for builtin pragma
by choroba (Cardinal) on Oct 19, 2023 at 18:17 UTC
    I love the idea! Thank you for moving it forward.

    If I had to nitpick, it would probably be about the chosen names:

    1. I'm not sure about the :ref, as :weak are also about references, so someone could be surprised :ref doesn't include :weak.
    2. :round is usually a function of its own (see POSIX) but it's not part of :round, which might again be confusing. Maybe :rounding? It's a bit longer than the rest, though...

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      G'day choroba,

      ++ Thanks for the feedback.

      None of those tag names are set in stone. I'm certainly open to suggestions for alternatives.

      For your point 1, maybe:

      • :weak - weaken, unweaken, is_weak
      • :refinfo - blessed, refaddr, reftype
      • :ref - :weak, :refinfo

      For point 2, I wasn't entirely sold on :round myself but couldn't think of anything better. Perhaps await suggestions from others.

      — Ken

        Maybe :numeric instead of :round? That provides some future proofing in the event functions like looks_like_number are added at a later date.

        Although maybe that causes issues as then different module versions would load different subs.

Re: RFC: Export tags for builtin pragma
by Haarg (Priest) on Oct 20, 2023 at 01:17 UTC

    The problem with tags like this is that adding anything to them later is essentially a compatibility break. I'd say they are pretty unlikely to be added.

    With Perl 5.40, when they start being stabilized, it will be possible to import all of the stable builtins using a version tag, similar to features.

      G'day Haarg,

      ++ Thanks for your opinion.

      "I'd say they are pretty unlikely to be added."

      I'll see what others have to say; however, on the basis of "nothing ventured, nothing gained", I may still test the waters.
      [large unlikelihood = small likelihood :-) ]

      — Ken

      I'd rather just see them imported as part of "use v5.40". Any reason not to just import them all? Most of these have been occupying our module namespace for decades anyway.
Re: RFC: Export tags for builtin pragma [Proposal dropped]
by kcott (Archbishop) on Oct 26, 2023 at 08:19 UTC

    Thanks to all who provided feedback. Unfortunately, I've decided to drop this proposal; there are two main reasons.

    Firstly, I see in "Perl v5.39.4: perldelta", under "Updated Modules and Pragmata", that builtin will allow a :5.40 tag (and presumably higher version numbers in subsequent releases) which has the same functionality as my proposed :stable tag.

    Secondly, there was lack of consensus on many of the proposed tags; e.g. should :weak be included in :ref; was :round a good name.

    When Perl v5.40.0 is released, I'll probably just be writing:

    use builtin ':5.40';

    unless I only want a restricted set, such as

    use builtin qw{true false};

    Thanks again to all who participated in this RFC.

    — Ken

      The intent is that use v5.40; will automatically do the equivalent of use builtin ':5.40';. This hasn't been implemented yet, but it should be by the time of the final release.

        ++ Thanks for the heads-up. I'll keep my eye on the deltas.

        — Ken

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://11155064]
Approved by choroba
Front-paged by choroba
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-09-17 05:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (22 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.