5 ms·
Moose is a killer library for Perl. I really miss roles when working in other languages. I often feel like I'm fighting the language if I can't split out some c
by MichaelBurge 12y ago
Moose is a killer library for Perl. I really miss roles when working in other languages. I often feel like I'm fighting the language if I can't split out some common program logic into a separate module and compose it in.
I can get by in C++(using multiple inheritance and the CRTP), and Haskell(with typeclasses).
D has some interesting features - like template mixins - that look promising, but I haven't been gutsy enough to use it for any new project.
- csirac2 12y agoI'm glad I'm not the only one! Explaining why I'd possibly miss anything from the Perl world can sometimes be like pulling teeth.
- TheDauthi 12y agoI'm a heavy Rubyist these days, and Moose is one of the very few things I miss from the realm of Perl. Here's a fun game: the next time someone asks you what technologies you work with or languages you prefer, somehow work in that you like Perl, at least Modern Perl with Moose. Count which one occurs most frequently: people backing away like you've begun frothing at the mouth, people asking if you've ever heard of ANOTHER_TECHNOLOGY (usually Ruby, sometimes Python), and people who assume you're a sysadmin who occasionally scripts something (they'll ask if you've ever used Puppet or Chef).
- NAFV_P 12y ago> Count which one occurs most frequently: people backing away like you've begun frothing at the mouth, people asking if you've ever heard of ANOTHER_TECHNOLOGY (usually Ruby, sometimes Python), and people who assume you're a sysadmin who occasionally scripts something (they'll ask if you've ever used Puppet or Chef). If you were to 'speak' Perl verbatim, you probably would start frothing at the mouth (from exertion, not from a deadly disease).
- rurounijones 12y agohttps://github.com/peczenyj/MooseX https://github.com/peczenyj/MooseX may be of interest to you then, there was a reddit post about it a few days ago. To be honest, as a ruby person, I don't really see what benefits it brings to ruby but maybe I am just missing something.
- girvo 12y agoRoles seem conceptually similar to Traits in Hack/PHP, right? If so, yeah, they're one of my favourite features, being able to rip out some common code and just do use Something\CoolTrait; inside of a class is just great!
- Joeri 12y agoMaybe it's just me, but I've never seen a use for traits. Any time I need to reuse logic across classes, I'll make it a proper class and compose it in as a member. What sort of functionality do you use traits for?
- gamache 12y ago> I'll make it a proper class and compose it in as a member. You've just implemented traits.
- Joeri 12y agoIn PHP traits override methods which is something other than being a member object (though you can use traits to do that as well). http://php.net/manual/en/language.oop5.traits.php http://php.net/manual/en/language.oop5.traits.php
- zsoltgyongyosi 12y agoI used traits to extract common functionality from POPOs.
- wschroed 12y agoThat's a delegation strategy, which is a very limited form of composition. A class with a trait/role can be queried for that interface: smile() if $my_object->does('SomeTrait'); Methods provided by a trait/role have direct access to $self. Also, Moose gives you the ability to apply traits to classes that are not predefined with those traits: use Moose::Util; my $instance = Moose::Util::with_traits('MooseClass', 'MyTrait')->new(%params); You can parameterize roles (as in, pass parameters that affect what the role provides). If you put some method modifiers into your roles, you can enhance existing functionality; for example, you can add logging, memoization, and persistence, all without the class having those features beforehand. In other words, roles/traits make your OOP functionality much more composable.
- sigzero 12y agoThey are taking some of it into the core. So maybe that will help people use it more.