62

I just installed Perl 5.18, and I get a lot of warnings like this,

given is experimental at .\[...].pl line [...].
when is experimental at .\[...].pl line [...].
Smartmatch is experimental at C:/strawberry/perl/site/lib/[...] line [...].

Looking into these warnings -- which I've never heard mentioned anywhere -- I was only able to find this in two places,

The Perl Delta still does the most to give mention as to what's happening with those features. It's halfway down buried in the pod,

Smart match, added in v5.10.0 and significantly revised in v5.10.1, has been a regular point of complaint. Although there are a number of ways in which it is useful, it has also proven problematic and confusing for both users and implementors of Perl. There have been a number of proposals on how to best address the problem. It is clear that smartmatch is almost certainly either going to change or go away in the future. Relying on its current behavior is not recommended. Warnings will now be issued when the parser sees ~~, given, or when.

I'm confused at how the most significant change in Perl in the past 10 years could be pulled. I've started using given, when, and smartmatch all over the place. Is there any more information about these futures? How is anyone finding them "confusing?" How are these features likely to change? Is there a plan to implement these features with a module?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468

3 Answers3

37

There are problems with the design of smart-matching. The decision of what any given TYPE ~~ TYPE should do is most often unobvious, inconsistent and/or disputed. The idea isn't to remove smart matching; it's to fix it.

Specifically, ~~ will be greatly simplified, as you can see in a proposal by the 5.18 pumpking. Decisions as to how two things should match will be done with helpers such as those that already exist in Smart::Match.

... ~~ any(...)

It is much more readable, much more flexible (fully extensible), and solves a number of problems (such as "When should X be considered a number, and when should it be considered a string?").

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ikegami
  • 367,544
  • 15
  • 269
  • 518
22

Some insights might be gained by reading rjbs's proposed changes to smartmatch. He is the pumpking (Perl release manager) after all, so his comments and his view of the future is more relevant than most. There is also plenty of community comment on the matter; see here for instance. The 'experimental' status is in effect because, since things are likely to change in the future, it is responsible to inform users of that fact, even if we don't know what those changes will be.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Joel Berger
  • 20,180
  • 5
  • 49
  • 104
10

Well, that's what's said in the description of the patch that downgraded this set of features to experimental:

The behavior of given/when/~~ are likely to change in perl 5.20.0: either smart match will be removed or stripped down. In light of this, users of these features should be warned. A category "experimental::smartmatch" warning should be issued for these features when they are used.

So while you can indeed turn these warnings off, with something like this (source):

no if $] >= 5.018, warnings => "experimental::smartmatch";

... it's just turning your eyes off the problem.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
raina77ow
  • 103,633
  • 15
  • 192
  • 229
  • 8
    It's not about how to turn these warnings off, it's about what's wrong with Smartmatch/given/when and how will they be remedying the problem. The roadmap is just "change ahead" with no certainty of direction. – Evan Carroll Jun 04 '13 at 20:48
  • Well, I've answered the part of the question I could. For `why it's confusing` part, I can only refer you to [this (hugely undervoted) answer](http://programmers.stackexchange.com/a/135828) - in my opinion, it describes the core point of the problem pretty darn well. ) But then again, SO is not about opinions, I suppose. – raina77ow Jun 04 '13 at 21:05
  • @EvanCarroll yes, that's what "experimental" means. It means "we don't know how this is going to work in the future, but there's a good chance it won't work like *this* and your code may break". – hobbs Jun 05 '13 at 04:15
  • 3
    BTW One can use [`use exporimental 'smartmatch';` pragma](https://metacpan.org/module/experimental) to turn the warnings off (instead of "official" and ugly way). – Grzegorz Rożniecki Jun 05 '13 at 08:32
  • On the bright side, the "official" and ugly way will actually work on interpreters v5.10 through v5.18 . I imagine folks will be required to support v5.18 for more than the next week. – tjd May 27 '14 at 18:08