Home coding Explaining Why Moose is Awesome – The Direct Way

Explaining Why Moose is Awesome – The Direct Way




Why: Moose makes Perl more Maintainable than Other Languages



How: Moose adds Static Typing to Getters and Setters


Bonus: Moose Eliminates Write Once Code





What You Can Do


 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
2 Comments  comments 
  • Sterling Hanenkamp

    I would be careful about saying that Moose adds static checking to attributes. It does add something that looks like type checking to attributes and it is very useful and very powerful, but it is not static type checking. Setting the isa on an attribute gives that attribute a type constraint, but this is more akin to input validation that it is to typing. Under the usual circumstances this distinction does not make much of a difference.

    It does make a difference which comes out most clearly when you perform type coercion. When coercion happens the system starts by guessing what type the value could be (from the list of available coercions) and then applies the coercion. In static typing, the type of the value is known at compile time. From the standpoint of analysis that’s a pretty big difference.

    • John Wang

      I agree with what you’re saying about the implementation details and in my conversations I make it clear that Moose doesn’t provide actual static typing but provides a similar benefit. Here, I try to suggest this by saying it’s a check on “setters” (“getters” should probably be removed for technical correctness) which I think of as a runtime check as opposed to an attribute which would happen at compile time.

      That being said, often times you only get 30 seconds to explain why something is powerful. In that context I want to explain why something is useful and worth looking into from a benefit perspective so it is important to use terminology that someone will understand, even if it is just a first approximation.

      From that perspective, do you think it is a useful description?