Catch-all proposal based on proxies

Mike Wilson mikewse at hotmail.com
Wed Dec 9 01:02:04 PST 2009


Mark Miller wrote:
> On Tue, Dec 8, 2009 at 2:12 PM, Mike Wilson wrote:
> > I'm guessing that a common use-case is trapping calls to all objects
> > delegating to a certain prototype, or all instances of a 
> > certain class.
> 
> It's not the use case that's motivating us to work on catchalls, but
> it may be an important use case. Let's assume it is.

Looking at the Use Cases section in your proposal it seems most
of your suggested use cases would be interesting to apply on an
object prototype/class level when targeting many objects, to 
avoid having to recreate the catch-all for every object and also
possibly adding dynamically generated methods in a common place
(like in Ruby/ActiveRecord).
Hearing that you are not certain that this is indeed an important
use case, or maybe use case property, I wonder if I am missing
something? I have full respect for that you have thought this
through, so maybe there is something in the language or in other
Harmony plans that make this less interesting?

> > Do you have any thoughts on how this may be optimized? When 
> > having 10000 objects to trap, it seems more efficient to put 
> > the catch-all on a single augmentation point instead of 
> > creating and configuring 10000 proxies?
> 
> Have these 10000 objects inherit from a single proxy. The 
> trapping get/put calls on the handler provide the "receiver" 
> argument, which is the object on which the failed property 
> access was attempted.

This sounds interesting. It would be great if you could show a
code example? A good "demo" case could be mimicing the single
point catch-all and dynamic .find_by_* method generation for all
User objects in the ActiveRecord examples:
http://api.rubyonrails.org/classes/ActiveRecord/Base.html
(section "Dynamic attribute-based finders")

Best regards
Mike



More information about the es-discuss mailing list