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.
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.
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).
If you were to 'speak' Perl verbatim, you probably would start frothing at the mouth (from exertion, not from a deadly disease).
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.
use Something\CoolTrait;
inside of a class is just great!What sort of functionality do you use traits for?
You've just implemented traits.
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.