Front page | perl.perl5.porters |
Postings from January 2021
Re: Adding a try/catch syntax to Perl
Thread Previous
|
Thread Next
From:
Felipe Gasper
Date:
January 22, 2021 18:37
Subject:
Re: Adding a try/catch syntax to Perl
Message ID:
9DBD53B7-6277-4A93-895E-853DC34EEBB9@felipegasper.com
FWIW, I personally prefer the parens. It matches what I expect from JS, at least, and it fits things like the “isa” feature of Syntax::Keyword::Try.
-FG
> On Jan 22, 2021, at 1:34 PM, Philip R Brenan <philiprbrenan@gmail.com> wrote:
>
> Please change catch ($e) to catch $e so that millions of people in the decades to come do not have to waste thousands of man years of effort struggling to correctly parse and place pointless parentheses when a small amount of extra programming effort eftsoon could easily eradicate this evil necessity in its entirety and thereby save us all a lot of time. "Tempus fugit". "Ha una vita sola".
>
>
> On Fri, Jan 22, 2021 at 5:02 PM Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> wrote:
> I intend to add try/catch syntax. This has been one of the most
> frequently-requested of core syntax features - from both community
> sources like Freenode #perl and other core developers - so I do not
> anticipate this will be a contentious or debated idea.
>
> As many of the existing CPAN solutions all follow a very similar theme
> - including my own Syntax::Keyword::Try[1] - I expect I shall follow
> that pattern, and likewise do not anticipate that this will be
> considered controversial. Syntax::Keyword::Try has been the preferred
> module by Freenode #perl for a while now, and folks seem happy with it.
>
> I further intend it to be introduced as
>
> use feature 'try';
>
> Towards this goal, I have created a module Feature::Compat::Try[2] to
> simplify migration. Existing authors can
>
> use Feature::Compat::Try;
>
> in their current code, today, and import a configured version of
> Syntax::Keyword::Try which works on all Perl versions back to 5.16, and
> conforms exactly to the specification of the thing I want to add to
> core. (S:K:T additionally contains other features, experimental ideas,
> and past mistakes, that I do not intend to bring in at this time, hence
> the configuration).
>
> A brief summary, from its synopsis, is:
>
> use Feature::Compat::Try;
>
> sub foo
> {
> try {
> attempt_a_thing();
> return "success";
> }
> catch ($e) {
> warn "It failed - $e";
> return "failure";
> }
> }
>
> If anyone wishes to review in more detail the syntax and semantics,
> please read the documentation and unit-tests of this module. That is
> what I intend to implement exactly. You do not have to wait until I
> have a PR to actually implement it to do this - the earlier you do
> this, the better :)
>
>
> 1: https://metacpan.org/pod/Syntax::Keyword::Try
>
> 2: https://metacpan.org/pod/Feature::Compat::Try
>
> --
> Paul "LeoNerd" Evans
>
> leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
> http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/
>
>
> --
> Thanks,
>
> Phil
>
> Philip R Brenan
Thread Previous
|
Thread Next