Perl 5.20 和智能匹配和给定时间的命运 [英] Perl 5.20 and the fate of smart matching and given-when

查看:68
本文介绍了Perl 5.20 和智能匹配和给定时间的命运的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚安装了 Perl 5.18,我收到了很多这样的警告,

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

Perl Delta 仍然在提及这些功能发生的事情方面做得最多.它的一半埋在豆荚里,

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,

在 v5.10.0 中添加并在 v5.10.1 中进行了重大修订的智能匹配一直是一个常见的抱怨点.尽管它在很多方面都有用,但事实证明,它也给 Perl 的用户和实现者带来了问题和困惑.关于如何最好地解决这个问题,已经提出了许多建议.很明显,smartmatch 几乎肯定会在未来发生变化或消失.不建议依赖其当前行为.现在,当解析器看到 ~~、给定或何时会发出警告.

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.

过去 10 年来 Perl 中最重要的变化是如何发生的,我很困惑.我已经开始到处使用 givenwhensmartmatch.有没有关于这些期货的更多信息?怎么会有人觉得它们令人困惑"?这些功能可能会发生怎样的变化?是否有计划通过模块实现这些功能?

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?

推荐答案

智能匹配的设计存在问题.任何给定的 TYPE ~~ TYPE 应该做什么的决定通常是不明显的、不一致的和/或有争议的.这个想法不是删除智能匹配;这是为了修复它.

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.

具体来说,~~ 将大大简化,正如您在提案中所见 由 5.18 抽.关于两件事情应该如何匹配的决定将由助手完成,例如那些已经存在于 Smart::匹配.

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(...)

它更具可读性,更灵活(完全可扩展),并解决了许多问题(例如何时应将 X 视为数字,何时应将其视为字符串?").

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

这篇关于Perl 5.20 和智能匹配和给定时间的命运的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆