Apple Blocks added to C++?
Michel Fortin
michel.fortin at michelf.com
Wed Sep 2 00:40:07 PDT 2009
On 2009-09-02 00:27:46 -0400, S. <S at S.com> said:
> Been awhile since I posted.
>
> I was wondering what other people thought about this addition to C++ by
> Apple. Heh.
>
> http://arstechnica.com/apple/reviews/2009/08/mac-os-x-10-6.ars/10
I don't find the syntax that ugly. And I'd say the feature is at its
best when used with Grand Central Dispatch. As page 13 of this same
review says, it enables developer to transform synchronous operations
such as this:
NSDictionary *stats = [myDoc analyze];
[myModel setDict:stats];
[myStatsView setNeedsDisplay:YES];
[stats release];
into asynchrnous with minimal effort:
dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSDictionary *stats = [myDoc analyze];
dispatch_async(dispatch_get_main_queue(), ^{
[myModel setDict:stats];
[myStatsView setNeedsDisplay:YES];
[stats release];
});
});
Without it, you'd have to create a bunch of different functions,
probably accompanied by a context struct, to make this work,
complexifying the conde and making it harder to follow. It's just
syntaxic sugar when you think about it, but it's that syntaxic sugar
that makes it practical to express operations in a way they can run
asynchrnously.
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list