Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • So you want to mixin your bomb class and your girlfriend class to your current class:

    package Bomb;

    sub fuse    { ... }
    sub explode { ... }

    package Girlfriend;

    sub fuse    { ... }
    sub explode { ... }

    What happens when you want the Bomb::fuse method (because you can control the timing) but you also want the Girlfriend::explode method (because it's presumably non-lethal)? Now you have an ordering problem and you can't eliminate it. Of course, you could just use delegation, but that doesn't make life simple and that's part of what mixins are supposed to do. Traits allow you to solve this

    But what if you already have a fuse or explode method defined in your code? mixins overwrite that. traits don't. Further, the traits won't even compile if there are conflicts unless you explicitly tell them how to resolve the conflicts.

    Does another class want to know if you've implemented the Bomb methods? mixins don't really solve that (if you just use Girlfriend, it might have the false cognate problem, it might not). Traits, on the other hand, do solve that.

    Need to conditionally bring those methods in at runtime or apply them to individual instances? Traits will do that, too.