Jeremie Pelletier Wrote:
> There's a huge difference between complex code and long code, especially in
> compiled languages. Those 8 lines in your code are not convenient in that you
> don't get what they do on first sight. Declaring your things separately and
> then registering the closures to the queues would result in the exact same
> machine code being generated, but also be much easier to read.
I disagree. That depends on type of code and is also a matter of taste.
For example in JavaScript, where there's no difference between functions and
lambdas, I prefer to use deeply nested anonymous functions rather than function
declarations beforehand. I often find that more readable and I prefer
definition and use of the function in one place.
> The only place where I expect to see code unreadable like this is in
> scripting where the parser has an impact on the performance.
>
> I also don't get why you need two closures on two different queues. My take
> at this in D would look like:
>
> DispatchAsync({
> writefln("Look, async!");
> });
>
> No global queue to dispatch on the main queue, that's just redundant and
> slow, custom dispatcher that is portable, and D closures, simple and elegant
> :)
In that example global serial queue is used as synchronisation mechanism. It is
needed to interact with Cocoa UI properly.
Of course D has nicer syntax than C blocks. But in context of C, given its
already-awkward syntax for function types, limitations and compatibility
needed, blocks are quite good.