Re: Update to smartmatch
by Laurent_R (Canon) on Dec 25, 2017 at 21:27 UTC
|
Thanks stevieb for bringing up this issue.
I am quite happy that I've never used the smartmatch operator and the given construct for any production code in Perl 5 (although not for the reason that I was clever, but for the reason that our production machines run very old versions of Perl).
I don't know all the details, so I may be wrong, but it seems to me something is going wrong there. I very much respect Leon T., and I also respect Sawyer X., but it appears that the P5P process has gone somewhat amok.
Anyway, I think that anyone concerned with this issue will have some interest reading these detailed comments from brian d foy: https://www.effectiveperlprogramming.com/2017/12/beware-of-the-removal-of-when-in-perl-v5-28/.
| [reply] [d/l] [select] |
|
| [reply] [d/l] [select] |
|
Thank you, ikegami. In fact, I knew about the history of smartmatch and given (as well as lexical $_). I was only saying that I don't know the details on the most recent developments as described by Leon and brian (i.e. your point 6) and the discussions around these. But it's probably good to retell the story for the benefits of those monks who would not know or not remember.
| [reply] [d/l] [select] |
|
|
|
I also have not ever used "smartmatch" and friends. I have never encountered it in code I've worked on at various employers, and that's neither because they were so clever, nor because they were all using old perls. It's because of the incredible confusion and instability around the "features," and also because no good use case for using them has been presented. What exactly is the problem that it's supposed to solve, that cannot be elegantly (enough) solved with normal loop and conditional constructs?
I will not shed a tear if smartmatch/given/etc. are reimplemented so code that uses them breaks (I expect that CPAN modules that break will be fixed), or if it completely goes away for now (which I think is the most sensible suggestion in the p5p thread that encapsulates the current debate). However, I am alarmed at the process with which the changes have been already merged into bleadperl, as highlighted by LeonT and brian d foy. If that is the way things are going to get done, I fear that Perl will come to be viewed -- correctly -- as an unstable mess where there are no adults in charge.
In my opinion, that of a journeyman, workday Perl programmer, at the root of all this was the fiction that "Perl6" was a real thing in 2007, and the precipitous rush to implement many of its "features" in Perl v.5.10. Damian Conway and people who, like him, are outlandishly clever but also suffer from an excess of hubris, should be kept far away from the core of Perl!
The way forward always starts with a minimal test.
| [reply] [d/l] |
|
I also have not ever used "smartmatch" and friends. I have never encountered it in code I've worked on at various employers,
I think you're trying to prove they're not a desired features, but it's far more likely that you've worked a companies that sensibly avoid using experimental (unstable) features in production code.
It's because of the incredible confusion and instability around the "features,"
There's no confusion; smartmatching is an experimental feature, not a stable feature. This will still be the case in 5.28. Continue not using it unless you want to be a beta tester.
I am alarmed at the process with which the changes have been already merged into bleadperl
Aye, there were problems, which were resolved by the creation of the policy and ability to make new features experimental.
| [reply] |
|
|
On rare occasions I've found it very convenient for debugging purposes, such as when I want to quickly compare two arrays.
If I recall correctly, last time I used it I was "cleaning up" some old code and I wanted a quick way to double check that the output array from the old code and the output array from the new code were exactly the same.
Just another Perl hooker - My clients appreciate that I keep my code clean but my comments dirty.
| [reply] |
|
|
Re: Update to smartmatch
by ikegami (Patriarch) on Dec 26, 2017 at 20:20 UTC
|
Apparently, a lot of code on CPAN uses the experimental features, and are breaking as the result of the change you mentioned. Things are very much still quite in flux.
| [reply] |
|
imho, smartmatch is "experimental", will likely never be stable, and should not ever be used in any code on the CPAN. If it is used in any authored code, the documentation should state it clearly, and warn loudly.
| [reply] |
Re: Update to smartmatch
by choroba (Cardinal) on Feb 23, 2018 at 16:46 UTC
|
Post mortem from the Pumpking.
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord
}map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
| [reply] [d/l] |
Re: Update to smartmatch
by njahnke (Acolyte) on Feb 18, 2018 at 01:51 UTC
|
I use smartmatch to check a string against a list of precompiled regexen. I need to see if ANY of the regexen matches. If one does (I don't care which), then I do something with the capture group on the next line. That part is always the same - I just don't know which regex (if any) is going to match the input string. I don't know how to match a string against ANY regex in a list of them without smartmatch without using a loop construct with flow control. The difference is so big that I go out in public with `no warnings 'experimental::smartmatch'` at the top of my code just for this one use case. | [reply] |
|
Just join the regexes into one large regex. Use | to separate them, and use branch reset (?|...) to start counting the capture groups from 1 in each alternative.
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord
}map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
| [reply] [d/l] |
Re: smartmach updated? or something? perl5-porters did something somewhere and some porter commented about it
by Anonymous Monk on Dec 24, 2017 at 03:27 UTC
|
Hooray ... smartmatch has been gutted again?
Talk about out of context ...
Hehe, even the OP not interested to find out what the where what what all
| [reply] |
|
| [reply] |