Are MooseX::Declare and MooseX::Method::Signatures production ready?
Asked Answered
I

6

12

From the current version (0.98) of the Moose::Manual::MooseX are the lines:

We have high hopes for the future of MooseX::Method::Signatures and MooseX::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.

I noticed that for MooseX::Method::Signatures the change log for September 2009 mentions the removal of the "scary ALPHA disclaimer".
So, are these still "alpha"?
Would I still be considered one of the "more insane" to use them?

Intinction answered 23/2, 2010 at 22:15 Comment(0)
S
12

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

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. Don't use these if performance is an issue.

Stability

MooseX::Declare and MooseX::Method::Signature's external syntax is now stable. 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). 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. Devel::Declare itself is a hack - after it sees specific keywords (e.g. 'role', 'class', 'method') the Devel::Declare-using module must rewrite the source code by hand, with no interaction with the real Perl parser.

Corner cases may cause Perl to segfault. Or rewrite the source code badly, so you get syntax errors but have no idea what's causing them without -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. The ALPHA message may have gone, but this is still doing dark and scary things internally, and you should be prepared for that.

UPDATE

MooseX::Declare has not been updated much, and you may wish to look at alternatives such as 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.

Supercargo answered 24/2, 2010 at 1:20 Comment(3)
I'm not sure you can guarantee that the external syntax is stable since Moose has no such promises of stability itself.Quincunx
Note that while does coerce has a speed penalty, it's also one of the most awesome things around. Use it as appropriate, just don't use it for no reason :)Loferski
For the code-writing stuff, I've talked to some Moose people about using Moose in a pre-processor type workflow. A distribution processes Moosified.pm.PL, resolves all the Moose stuff, spits out non-Moose Perl code, and installs that. You can then look at the output to see what went wrong without having to wait until you run a program. If you don't need the dynamic, runtime stuff, I think that's the best way for Moose to go.Foulard
L
7

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

Loferski answered 23/2, 2010 at 23:52 Comment(2)
Thanks. My eventual replacement will probably have to learn Perl from scratch, so your comments on maintainability are particularly pertinent.Intinction
+1, but let me note that "more insane members of the community" is really conveying something other than what I think you're trying to say. Florian writes good and generally stable code. It's just that he also experiments a lot. Great things have come of that. As with all external dependencies, it's just important that one spends some time deciding when it's a prototype quality library or when it's considered tried and true.Jolyn
Q
5

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". I also know of two large companies with millions of visitors a month, who have MooseX::Declare in their production environment. I personally am happy with the stack I am provided with Moose and do not see a need yet to bring in MooseX::Declare. I know people who's opinion I deeply respect who refuse to write new code without the declarative sugar from 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.

Quincunx answered 23/2, 2010 at 23:42 Comment(2)
Thanks. It is probably good for me to remember that not everyone is as thrilled about Moose as I am. I use it so much, I had forgotten that fact.Intinction
It's not that people aren't thrilled by Moose, but they just value stability more. I think Moose and MooseX is really cool. I just need it to stabilize. :)Foulard
D
5

MooseX::Method::Signatures (MXMS), and MooseX::Declare which uses it, is not production ready. 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. My Macbook Pro can do about 6,000 simple method calls per second using MXMS vs 5,000,000 with plain Perl.

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. Both rely on the same underlying syntax modifying technique. (Full disclosure, I am the author of Method::Signatures.)

If you like MooseX::Declare but want the performance of Method::Signatures, try Method::Signatures::Modifiers.

Dolichocephalic answered 30/5, 2011 at 8:33 Comment(0)
F
4

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

Foulard answered 23/2, 2010 at 22:34 Comment(4)
Thanks for your answer. It sounds like you are reluctant to even use Moose.Intinction
I think Moose is really cool. I'm just reluctant to pay attention to it every day to see if I have to redo lots of stuff. I have to get things done, and not relying on a quickly changing set of modules isn't the way to make progress. As I said, it's not particular to Moose.Foulard
Thanks. That makes sense. So, do you build all of your objects from scratch?Intinction
I make most of my objects by calling constuctors in CPAN modules. :)Foulard
P
3

MooseX::Declare and MooseX::Method::Signatures are working well but they can have really nasty penalty depending on what does your code do. This can be fixed by just not using method keyword or using 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). 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.

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

It may be worth it to get rid of Perl argument shifting hell.

Proudman answered 28/10, 2012 at 12:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.