Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl 5.20 and the fate of smart matching and given-when

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,

  • perldelta for 5.18, which only really mentions insofar as to say that the feature has been downgraded to experimental?
  • this nntp.perl.org post

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?

like image 247
NO WAR WITH RUSSIA Avatar asked Jun 04 '13 20:06

NO WAR WITH RUSSIA


2 Answers

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?").

like image 143
ikegami Avatar answered Sep 20 '22 21:09

ikegami


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.

like image 23
Joel Berger Avatar answered Sep 20 '22 21:09

Joel Berger