[Adium-devl] HOM

Colin Barrett timber at lava.net
Sat Nov 11 13:57:33 UTC 2006


I've heard some rumblings from David about good performance, but can  
you give us an idea of how say, the initial example:

NSEnumerator *e = [someCollection objectEnumerator];
NSString *str;
NSMutableArray *r = [NSMutableArray array];
while ((str = [e nextObject]))
	if ([str hasPrefix:@"a"])
		[r addObject:str];

compares to:

NSMutableArray *r = [someCollection selectWhere:MSG(hasPrefix:@"a"),  
nil];

in terms of performance?

-Colin

On Nov 11, 2006, at 3:18 AM, Ofri Wolfus wrote:

> Hi guys,
>
> As some of you may know, I've been working on a higher order  
> messaging (HOM) implementation[1] for some time now, and I'd like to  
> suggest it for Adium. For those of you who are not familiar with the  
> HOM concept, it's basically a way to pass messages as arguments to  
> other messages (see http://www.metaobject.com/papers/Higher_Order_Messaging_OOPSLA_2005.pdf 
>  for the OOPSLA paper about HOM). In practice, probably the most  
> common usage pattern for HOM is in iterations over collections.  
> Instead of writing:
> NSEnumerator *e = [someCollection objectEnumerator];
> NSString *str;
> NSMutableArray *r = [NSMutableArray array];
> while ((str = [e nextObject]))
> 	if ([str hasPrefix:@"a"])
> 		[r addObject:str];
>
> you'd just do NSMutableArray *r = [someCollection selectWhere:MSG 
> (hasPrefix:@"a"), nil]; where -selectWhere: is a method that accepts  
> variable number of messages, sends them by order to each member of  
> the collection, and returns the objects that returned YES for the  
> last message. Another example for it will be NSArray  
> *availableContacts = [contacts selectWhere:MSG(status), MSG 
> (isEqualToString:@"Available"), nil];.
> As you might have guessed, MSG() is a macro that returns an  
> autoreleased Message instance ("Message" is the class's name) which  
> can then be passed around like any other object.
>
> In my experience, using HOM can greatly simplify code in some common  
> cases, which I think will do only good to Adium's huge code-base.
>
> What do you think?
> - Ofri
>
> - - - - - - - - - - - - - - - - - - -
> http://www.dpompa.com
> - - - - - - - - - - - - - - - - - - -
>
> [1] http://www.dpompa.com/?page_id=4
>
> _______________________________________________
> Adium-devl mailing list
> Adium-devl at adiumx.com
> http://adiumx.com/mailman/listinfo/adium-devl_adiumx.com





More information about the devel mailing list