Stories
Slash Boxes
Comments
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.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Not completely into Moose yet, but isn't a role the equivalent of a Java interface?

    In that case, the behaviour you describe has been implemented there as a intended feature: a regular class *implements* the interface.

    Additionally, a role seems to also have the function of an abstract class as well. In Java, overriding concrete methods is, again, a feature you want.

    If you don't want to override a method simply do not include a overloading method in the implementing class.

    It looks like a (sensible) design dec

    • Roles are far more than interfaces. I strongly recommend reading up on them to understand what they do. The protect (usually) against method collision and they provide a default implementation. If you want to use one like an interface, it's simple:

      package MyRole::DoesSomething;

      use Moose::Role;
      requires qw(
          save
          search
      );

      And now your classes (or some other role composed into said classes) must provide save and search methods.

      However, if you have this:

      package MyRole::DoesSomethi

      • And the class using the role also has an 'is_deletable' method, than this potentially very important behavior is silently discarded.

        For a definition of "silently" which means "Code I explicitly wrote in my class itself", perhaps.

        What if you extracted all behavior into roles and composed them into classes? I think that would produce the desired results.

        • Still if you redefine a sub in standard procedural code - just as explicitely - you'll get a warning if you have warnings on.
          • Still if you redefine a sub in standard procedural code - just as [explicitly]...

            If you override a method in OO code (the paradigm under discussion) explicitly, you get no warning or error.

            Changing this default behavior is like resolving method dispatch at compile time. That's fine for certain languages, none of which have "Perl" in their names.

            • Overriding methods in subclasses is a standard technique - there is no warning, because it is needed and there is no other way. In the case of roles there is a different way (as the recently anounced solution shows). So why not have this useful warning?
              • Class-local overriding of composed role methods is a standard technique too. It's been in the Perl 6 role specification for years. I have code which relies on it -- and that code predates Moose.

                I fail to understand the value of adding a default warning for intended, specified, useful behavior -- especially behavior you can't accidentally back into.

                • We get warnings for undefined variables because that might be a problem. It's trivial to suppress if you really meant it.

                  If your class silently overrides a role's method, that might be a problem. By issuing a warning, I can be alerted to a potential issue and it's trivial to suppress the warning if I really meant it. I've lost too many hours debugging this silent behavior to think I'll be convinced otherwise.

                  • If your class silently overrides a role's method....

                    How do you silently write a method? Every time I've written a method, I've done so deliberately.

                    Should there be a warning if you accidentally inherit from the wrong class? How about a warning if you mistype the name of your class? What if the name of the file and its directory path doesn't match the name of the package or class contained? I've made all of those mistakes, and they've all been difficult to debug -- but I don't know any usable heuristic

                    • How do you silently write a method? Every time I've written a method, I've done so deliberately.

                      He didn't say silently write a method he said silently override a method. Big difference. On a big project if there are several classes using a Role and that Role in the future adds a method the author now has to check every class that uses that Role to make sure there are no name clashes. If he ads a method that clashes with other Roles being used at the same time he'll get an error. But if that clash is with an class method he gets no such help.

                      Now imagine the author of the Role has no control over classes that use it (they are in another project or the Role is on CPAN and is being used by other CPAN modules), now the author of the Role is stuck. He can't add any new methods to his Role. That's the potential problem that this warning will .. um .. warn about.