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
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
On Warnings (Score:1)
This is not a case where the computer can identify problems with certainty. The compiler cannot judge your intent. Did you make a typo in the name of a class-local method such that it collides with the name of a composed method? Did you forget to read the documentation? Did you do it deliberately? Did someone up
Re: (Score:2)
Please note that I'm not trying to change your opinion here because it's obvious that we strongly disagree here. I provide this for anyone else who may be reading this.
This is not a case where the computer can identify problems with certainty. The compiler cannot judge your intent.
And that's why the warning is so desperately needed. If I inherit from A and B and both provide a "foo" method, I usually get the one that I've inherited from first. One could argue that I forgot to read the documentation or that I did it deliberately, but just like the composition problem I list above, there's no way that the compiler can
Re:On Warnings (Score:1)
Yet when I override multiple methods (or all of the methods) from a role for the purpose of complete allomorphism or delegation, your approach means that I have to exclude every one of them explicitly, which is mere busy work and syntactic noise and actively impairs the readability of the code, disable a warning against a valid design goal of roles, or I live with a compiler warning which tells me that I have very well done precisely what I intended to do.
Tell me with a straight face that it's not crazy to apply a role to a class and then immediately list all of the methods you don't want to compose from the role into the class because they appear in the class immediately after the role application.
As I said in my other reply, if your intent is to subtly suggest that people treat roles as mere super mixins, the on-by-default warning is a great idea.
Yes. That's the problem exactly. If you know that you will never take advantage of explicit class-local overrides and that you know that any class-local overrides are mistakes, by all means enable the warning locally in your own code. It's no problem there. You have a good heuristic for knowing that collisions are error conditions, because your coding standards (I presume) recommend against class-local overrides.
You don't know that about my own code, so please don't make the compiler try to help me by warning me that my code behaves exactly as I intend it to behave -- and not just the code itself, but the intent and design of roles.
Reply to This
Parent
Re: (Score:2)
For the case of overriding everything or almost everything and the role is not simply an interface, then yes, the work to exclude all of the role's methods would be annoying. That's the only interesting argument I've heard from this entire discussion and had the discussion started out with this, then things might have gone easier.
The problem is that your solution is still throwing away information, my solution can be cumbersome at times. So the reality is that this is a syntax issue. If a good, clean syn
Re: (Score:1)
mst has some very nice examples using
MooseX::Declare, where you provide a block after applying a role. Any method you define in that block very obviously takes precedence over methods composed from the role.Re: (Score:1)
Re: (Score:2)
I can easily imagine this. If you simply want to say "I provide this behavior" but your implementation differs significantly, you might override all of the roles (this is different from an interface because the role can also provide an implementation). The issue is that this is the use case that chromatic wants to support and I'm against silently discarding behavior.
Re: (Score:1)
Re: (Score:2)
Let's say that you can serialize an object as HTML. You might use the role Role::Serializable::HTML with a &serialize method. Then someone can ask:
By providing a name for the behavior, you are guaranteeing to someone that you provide a &serialize method and that it will serialize the object as HTML.
However, and this is chromatic's concern, it's quite reasonable that the object might want to use that r
Re: (Score:1)
I've written a lot of mock objects, and I've had to work around a lot of code which performs its own type checking. That can interfere with the work of mock objects. I plan to write an article with more concrete examples soon, but for now I hope it's not too abstract to say that the question "Is this entity a member of an inheritance hierarchy at this point or lower?" is much less interesting and much more difficult than the question "Does this entity perform the behavior I expect?"
Re: (Score:1)
Tell me with a straight face that it's not crazy to use a module and then be forced to list all of the methods that you want to import because it didn't define @EXPORT. Particularly when the only reason why someone would want to use that module is to get access t
Re: (Score:1)
The important difference is that roles have always had the explicit design goal of not enforcing any particular implementation decision to take advantage of them.
Re: (Score:1)
The fact that someone has a legitimate design goal that creates action at a distance doesn't necessarily make the decision to create action at a distance a good idea.
In a similar spirit I would not be opposed to an optional warning if my subclass overrode a parent class's method and didn't, say, provide an attribute that says, "Yes, this is an intentional override, don't warn." You might find having to type :override annoying, but I would find it invaluable. (I also know that I have a snowball's chance in
Re: (Score:1)
I believe it's easier to argue that inheriting or composing in methods is more action at a distance than declaring them locally. Perhaps prototype OO systems are clearest by this metric.