简体   繁体   English

是MooseX :: Declare和MooseX :: Method ::签名生产准备好了吗?

[英]Are MooseX::Declare and MooseX::Method::Signatures production ready?

From the current version (0.98) of the Moose::Manual::MooseX are the lines: Moose :: Manual :: MooseX当前版本(0.98)开始

We have high hopes for the future of MooseX::Method::Signatures and MooseX::Declare . 我们对MooseX::Method::SignaturesMooseX::Declare的未来寄予厚望。 However, these modules, while used regularly in production by some of the more insane members of the community, are still marked alpha just in case backwards incompatible changes need to be made. 然而,这些模块虽然经常被社区中一些更疯狂的成员用于生产,但仍然标记为alpha,以防万一需要进行向后不兼容的更改。

I noticed that for MooseX::Method::Signatures the change log for September 2009 mentions the removal of the " scary ALPHA disclaimer ". 我注意到,对于MooseX::Method::Signatures ,2009年9月的更改日志提到删除了“ 可怕的ALPHA免责声明 ”。
So, are these still "alpha"? 那么,这些仍然是“阿尔法”吗?
Would I still be considered one of the "more insane" to use them? 我还会被认为是使用它们的“更疯狂”之一吗?

I'd say they are production ready - I'm using them in production - but there are several things to consider: 我说它们已经准备好了 - 我正在生产中使用它们 - 但有几件事需要考虑:

Performance 性能

MooseX::Declare and dependencies do almost all of their magic at compile time. MooseX::Declare和dependencies在编译时几乎完成了所有的魔法。 Depending on the size of your program, you might find anywhere from half a second to several seconds of additional initialization overhead. 根据程序的大小,您可能会发现从半秒到几秒的额外初始化开销。 If this a problem, don't use MooseX::Declare . 如果这是一个问题,请不要使用MooseX :: Declare

At runtime, the main overhead is type and argument checking, which you should (ideally) be doing anyway. 在运行时,主要的开销是类型和参数检查,你应该(理想情况下)正在进行。 That said, Moose type constraints have some overheads, namely coercion and the more complex (MooseX::Types::Structured-style) constraints. 也就是说,Moose类型约束有一些开销,即强制和更复杂(MooseX :: Types :: Structured-style)约束。 Don't use these if performance is an issue. 如果性能问题,请不要使用这些。

Stability 稳定性

MooseX::Declare and MooseX::Method::Signature's external syntax is now stable. MooseX :: DeclareMooseX :: Method :: Signature的外部语法现在很稳定。 But it is important to know that the internals are subject to extreme change. 但重要的是要知道内部结构会发生极端变化。 (fortunately, changes for the better) (幸运的是,变化更好)

To give you an idea, the signature itself is grabbed using a big block of C code stolen from the Perl tokenizer (toke.c). 为了给你一个想法,签名本身是使用从Perl tokenizer(toke.c)窃取的大块C代码来获取的。 This can break in some situations since it isn't actually parsing anything. 在某些情况下,这可能会破坏,因为它实际上并没有解析任何东西。 The bit inside the brackets is parsed using PPI , which is designed for pure Perl, but the resulting PPI tree is then hacked up to get something useful. 括号内的位使用PPI进行解析, PPI是为纯Perl设计的,但是生成的PPI树会被黑客攻击以获得有用的东西。 Devel::Declare itself is a hack - after it sees specific keywords (eg 'role', 'class', 'method') the Devel::Declare-using module must rewrite the source code by hand, with no interaction with the real Perl parser. Devel ::声明自己是一个黑客 - 在看到特定关键字(例如'role','class','method')后,Devel :: Declare-using模块必须手动重写源代码,不与真实交互Perl解析器。

Corner cases may cause Perl to segfault. 拐角情况可能导致Perl发生段错误。 Or rewrite the source code badly, so you get syntax errors but have no idea what's causing them without -MO::Deparse . 或者严重重写源代码,因此您会遇到语法错误,但不知道是什么导致它们没有-MO::Deparse If you mess up the MooseX::Declare syntax by accident, there is no guarantee that the module will detect this and give you a sensible error. 如果您意外地弄乱了MooseX :: Declare语法,则无法保证模块会检测到这种情况并给您一个合理的错误。 The ALPHA message may have gone, but this is still doing dark and scary things internally, and you should be prepared for that. ALPHA的消息可能已经消失,但这仍然在内部做着黑暗和可怕的事情,你应该为此做好准备。

UPDATE UPDATE

MooseX::Declare has not been updated much, and you may wish to look at alternatives such as Moops . MooseX :: Declare尚未更新,您可能希望查看Moops等替代品。 Personally, I have decided to stick with pure Moose until Perl itself begins to support class/method/has syntax natively, which is possibly on the cards . 就个人而言,我决定坚持使用纯Moose,直到Perl本身开始支持class / method /具有本地语法,这可能就在卡片上

I think it's a matter of differing perspectives as much as anything -- rafl is one of the aforementioned "more insane members of the community" while Rolsky is more conservative. 我认为这是一个不同观点的问题 - rafl是上述“社区中更疯狂的成员”之一,而Rolsky则更为保守。 It's up to you to decide who you agree with, and really I think that the most important variable is your own code. 由你决定你同意谁,我认为最重要的变量是你自己的代码。

MooseX::Declare is good code. MooseX :: Declare是很好的代码。 It won't randomly blow up your machine, it's not awful for performance, and it offers a lot of nifty stuff while reducing the amount of boilerplate that you have to write. 它不会随机炸毁你的机器,它的性能并不糟糕,它提供了很多漂亮的东西,同时减少了你必须编写的样板量。 But it might change in the future, making your code refuse to compile until it's updated; 但它可能会在未来发生变化,使您的代码在更新之前拒绝编译; it might make your editor and other development tools confused when it sees syntax that it can't parse, it might piss off your collaborators by making them learn a new module to work with your code, or it might piss off your boss by making it so any future maintainer has to learn a new module to work with your code. 当它看到无法解析的语法时,它可能会让你的编辑器和其他开发工具感到困惑,它可能会让你的协作者学习一个新的模块来处理你的代码,或者它可能会让你的老板感到厌烦所以任何未来的维护者都必须学习一个新的模块来处理你的代码。 Which of those things apply to you, and to what degree? 哪些事情适用于您,以及在何种程度上? You know better than I do, I hope. 我希望你比我更清楚。

There are people who feel that the maturity and stability of MooseX::Delcare , Devel::Declare on which it's based, or even Moose itself are not yet ready for "prime time". 有些人认为MooseX::DelcareDevel::Declare的成熟和稳定性,甚至是Moose本身还没有为“黄金时间”做好准备。 I also know of two large companies with millions of visitors a month, who have MooseX::Declare in their production environment. 我也知道两家拥有数百万访客的大公司,他们在生产环境中拥有MooseX::Declare I personally am happy with the stack I am provided with Moose and do not see a need yet to bring in MooseX::Declare . 我个人对我提供给Moose的堆栈很满意,并且看不出需要引入MooseX::Declare I know people who's opinion I deeply respect who refuse to write new code without the declarative sugar from MooseX::Declare . 我知道那些我非常尊重的人,如果没有MooseX::Declare的声明性糖, MooseX::Declare拒绝编写新的代码。

All of this is to say, the decision on whether something is or is not production ready is highly dependent upon your production environment, your development needs, and taste for risk. 所有这一切都可以说,关于某件事是否生产准备的决定在很大程度上取决于您的生产环境,您的发展需求和风险品味。 Without being in your shoes we can't possibly give an informed decision as to how well any given tool matches that profile. 如果没有您的帮助,我们无法就任何给定工具与该配置文件的匹配程度做出明智的决定。

It depends on what you mean by "production ready". 这取决于“生产就绪”的含义。 I wouldn't depend on them until their velocity slows down quite a bit. 我不会依赖它们,直到它们的速度减慢很多。 I like my production stuff to not need frequent care from external code changes, API adjustments, and so on. 我喜欢我的制作工具,不需要经常关注外部代码更改,API调整等等。 That's not something particular to Moose, but any young project. 这不是穆斯所特有的,而是任何年轻的项目。

You have to judge how much that matters to you. 你必须判断对你来说有多重要。 In some situations, pushing stuff into production is a lengthy process, so you must be circumspect with such things. 在某些情况下,将产品推入生产是一个漫长的过程,所以你必须对这些事情保持谨慎。 At the other extreme, some places let you edit files directly on the production server. 在另一个极端,某些地方允许您直接在生产服务器上编辑文件。 That is, you have to define your tolerance before anyone can tell you which side a given MooseX module is on. 也就是说,在任何人可以告诉您给定的MooseX模块在哪一侧之前,您必须定义容差。

MooseX::Method::Signatures (MXMS), and MooseX::Declare which uses it, is not production ready. MooseX :: Method :: Signatures(MXMS)和使用它的MooseX :: Declare不是生产就绪的。 This is not because the code isn't stable, but because it is appallingly slow. 这不是因为代码不稳定,而是因为它非常慢。 Simply using the method keyword, no types or arguments, is a 500-1000x runtime performance hit over a regular method call . 简单地使用method关键字,没有类型或参数,是常规方法调用500-1000x运行时性能命中 My Macbook Pro can do about 6,000 simple method calls per second using MXMS vs 5,000,000 with plain Perl. 我的Macbook Pro可以使用MXMS每秒执行大约6,000个简单方法调用,使用普通Perl可以执行5,000,000个简单方法调用。

Method::Signatures , in contrast, has almost no performance hit above what it would normally cost to do the requested checks. 方法::签名 ,相比之下, 签名几乎没有达到执行所请求检查通常所花费的性能。 The syntax is almost exactly the same as MXMS and it supports Moose (and Mouse) types. 语法与MXMS几乎完全相同,它支持Moose(和Mouse)类型。 Both rely on the same underlying syntax modifying technique. 两者都依赖于相同的底层语法修改技术。 (Full disclosure, I am the author of Method::Signatures.) (完全披露,我是Method :: Signatures的作者。)

If you like MooseX::Declare but want the performance of Method::Signatures, try Method::Signatures::Modifiers . 如果您喜欢MooseX :: Declare但想要了解Method :: Signatures的性能,请尝试Method :: Signatures :: Modifiers

MooseX::Declare and MooseX::Method::Signatures are working well but they can have really nasty penalty depending on what does your code do. MooseX::DeclareMooseX::Method::Signatures运行良好,但根据你的代码做什么,它们可能会有非常严重的惩罚。 This can be fixed by just not using method keyword or using Method::Signatures::Modifiers . 这可以通过不使用method关键字或使用Method::Signatures::Modifiers

Performance penalty I am seeing is around 2-5x compared to Method::Signatures::Modifiers (5x being mostly for one specific class I was using). Method::Signatures::Modifiers相比,我看到的性能损失大约是2-5倍(5x主要用于我正在使用的一个特定类)。 And it seems that it is mostly compile time or maybe first time initialization, because it is getting under 2x when the computation is longer. 并且它似乎主要是编译时间或者可能是第一次初始化,因为当计算时间更长时,它会低于2倍。

Method::Signatures::Modifiers has better errors but you have to turn this optimization off when you use debugger (it goes haywire because it does not see these methods, you can see for yourself in -MO=Deparse output). Method::Signatures::Modifiers有更好的错误,但是当你使用调试器时你必须关闭这个优化(因为它没有看到这些方法而-MO=Deparse ,你可以在-MO=Deparse输出中看到-MO=Deparse )。

It may be worth it to get rid of Perl argument shifting hell. 摆脱Perl争论转移地狱可能是值得的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM