Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Re: Why breaking can() is acceptable

by tilly (Archbishop)
on Apr 06, 2004 at 22:53 UTC ( #343155=note: print w/ replies, xml ) Need Help??


in reply to Re: Why breaking can() is acceptable
in thread Why breaking can() is acceptable

I'm sure that I don't really understand the way that you described that, likely because I have not read the rest of A12 yet.

However if you haven't nailed that part of the specification down, this discussion has convinced me that it would be a definite improvement to have a wildcard decision on whether to handle a method. That is, instead of writing something like an AUTOLOAD, you would write a method named something like CAN, which would dynamically decide whether or not to accept this method, and if it does, returns the subroutine that does it.

In thinking about it, I've had trouble coming up with anything that you'd want to do with a reasonable AUTOLOAD which cannot readily be duplicated by a CAN that works like this. Furthermore while it is very hard to make multiple inheritance and AUTOLOAD cooperate, this CAN strategy cooperates with multiple inheritance rather smoothly. In fact it returns the best possible for can() to "definitely has a method of this name", even in the face of multiple inheritance and wildcard methods.

Unfortunately if a user wanted to implement this in Perl 6, as I understand your paragraph they would not be able to pass the extra information to can() that, "I can really tell you whether I'll do that". Which prevents can() from giving the answer that we probably really wanted it to give.

In fact I'm seriously thinking of writing a module named something like UNIVERSAL::AUTOLOAD_CAN which implements a UNIVERSAL::AUTOLOAD and UNIVERSAL::can that implements this solution in Perl 5. This would make it possible to get can(), AUTOLOAD and multiple inheritance to play together. (But only if you write no other AUTOLOADs!)


Comment on Re: Re: Why breaking can() is acceptable
Re: Re: Re: Why breaking can() is acceptable
by TimToady (Parson) on Apr 07, 2004 at 17:50 UTC
    I think this will work out ok if .meta.can, when it's looking for wildcarding classes, distinguishes classes that define their own .can from those that don't, and only adds autoloaders to the end of the list that aren't shielded by a corresponding .can method. (The problems Perl 5 has with defining a .can method in a class shouldn't arise in Perl 6, which tries to prefer "next" semantics to "super" semantics. At worst we'll require people to say "next METHOD" at the end of each such .can method definition.)
      If I make a few assumptions about how .meta.can works, that should work out. (As long as you're aware of the issue and want it to work out, I'm sure that you can fulfill some set of conditions to make things work out.)

      I'm guessing that the programmer would still need to synchronize .can and AUTOLOAD in some way, but a mechanism to make that easy should be simple to add at the user level.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://343155]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (10)
As of 2014-12-26 15:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (171 votes), past polls