<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Java Closure Examples</title>
	<atom:link href="http://www.blog.dannynet.net/archives/87/feed" rel="self" type="application/rss+xml" />
	<link>http://www.blog.dannynet.net/archives/87</link>
	<description>Pondering Programming and Poetry</description>
	<pubDate>Thu, 28 Aug 2008 23:06:33 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: jamesladdcode.com &#187; Blog Archive &#187; Come on closures &#8230;</title>
		<link>http://www.blog.dannynet.net/archives/87#comment-107075</link>
		<dc:creator>jamesladdcode.com &#187; Blog Archive &#187; Come on closures &#8230;</dc:creator>
		<pubDate>Tue, 15 Jan 2008 21:28:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.blog.dannynet.net/archives/87#comment-107075</guid>
		<description>[...] Danny’s Blog -&#62;Java Closure Examples [...]</description>
		<content:encoded><![CDATA[<p>[...] Danny’s Blog -&gt;Java Closure Examples [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Danny&#8217;s Blog &#187; Blog Archive &#187; Closures And The Ars Rhetorica</title>
		<link>http://www.blog.dannynet.net/archives/87#comment-101231</link>
		<dc:creator>Danny&#8217;s Blog &#187; Blog Archive &#187; Closures And The Ars Rhetorica</dc:creator>
		<pubDate>Sun, 23 Dec 2007 16:24:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.blog.dannynet.net/archives/87#comment-101231</guid>
		<description>[...] to discuss only the most complex examples from the BGGA proposal. He &#8220;forgot&#8221; to show some examples of how closures might actually make life (and coding) a lot easier. Which one do you think is [...]</description>
		<content:encoded><![CDATA[<p>[...] to discuss only the most complex examples from the BGGA proposal. He &#8220;forgot&#8221; to show some examples of how closures might actually make life (and coding) a lot easier. Which one do you think is [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jeremy weiskotten</title>
		<link>http://www.blog.dannynet.net/archives/87#comment-71314</link>
		<dc:creator>jeremy weiskotten</dc:creator>
		<pubDate>Tue, 31 Jul 2007 15:19:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.blog.dannynet.net/archives/87#comment-71314</guid>
		<description>Just a nit: Instead of putting these methods in CollectionUtils or Collections, I would hope that Sun and other API vendors would implement them as instance methods in the Collection API implementations. Better OO, better API.

Only the syntax, and it's ugliness -- it's ugly because you don't understand it at a glance. Once you're used to the syntax, and you can grok the intent of the code at a glance, it may not stick out as ugly. A certain amount of syntactic decoration is necessary to fit it into a language that wasn't originally designed for it, in order to make it forward-compatible.</description>
		<content:encoded><![CDATA[<p>Just a nit: Instead of putting these methods in CollectionUtils or Collections, I would hope that Sun and other API vendors would implement them as instance methods in the Collection API implementations. Better OO, better API.</p>
<p>Only the syntax, and it&#8217;s ugliness &#8212; it&#8217;s ugly because you don&#8217;t understand it at a glance. Once you&#8217;re used to the syntax, and you can grok the intent of the code at a glance, it may not stick out as ugly. A certain amount of syntactic decoration is necessary to fit it into a language that wasn&#8217;t originally designed for it, in order to make it forward-compatible.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Olivier Descout</title>
		<link>http://www.blog.dannynet.net/archives/87#comment-43657</link>
		<dc:creator>Olivier Descout</dc:creator>
		<pubDate>Sat, 26 May 2007 13:57:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.blog.dannynet.net/archives/87#comment-43657</guid>
		<description>What I think is a shame about the Java closure examples you can usually find on the Net is that they are too obvious. Almost all of them can be solved with mere inner classes with a bit of verbosity. The five examples on this page fall into this. Of course, people need them to understand the basics, for it's not enough to understand the real power of closures.

In my opinion, one thing that really makes the BGGA closures powerful is the change of semantics for return, break, etc. It allows easy-to-write iteration using recursive algorithms, for instance: imagine you have a tree-based structure and you want to iterate through nodes or leaves of the tree. Today you have but one choice: to write an Iterator class, which un-recursifies the iteration. About 100-300 lines of code (!), which are quite tricky and hard to make bug-free.

With the BGGA closures, you just need to write your recursive algorithm (which is usually much simpler and shorter: down to 15-20 lines for classic tree-based algorithms?), and invoke the argument closure at every step of the iteration. If the closure decides to stop the iteration after the first or the second step, it's very easy to do it, no matter the recursion depth: the recursive algorithm doesn't have to be rewritten for that.

The best example I found on this matter is Neal Gaffer's one on his blog: http://gafter.blogspot.com/2007/03/closures-for-organizing-your-code.html</description>
		<content:encoded><![CDATA[<p>What I think is a shame about the Java closure examples you can usually find on the Net is that they are too obvious. Almost all of them can be solved with mere inner classes with a bit of verbosity. The five examples on this page fall into this. Of course, people need them to understand the basics, for it&#8217;s not enough to understand the real power of closures.</p>
<p>In my opinion, one thing that really makes the BGGA closures powerful is the change of semantics for return, break, etc. It allows easy-to-write iteration using recursive algorithms, for instance: imagine you have a tree-based structure and you want to iterate through nodes or leaves of the tree. Today you have but one choice: to write an Iterator class, which un-recursifies the iteration. About 100-300 lines of code (!), which are quite tricky and hard to make bug-free.</p>
<p>With the BGGA closures, you just need to write your recursive algorithm (which is usually much simpler and shorter: down to 15-20 lines for classic tree-based algorithms?), and invoke the argument closure at every step of the iteration. If the closure decides to stop the iteration after the first or the second step, it&#8217;s very easy to do it, no matter the recursion depth: the recursive algorithm doesn&#8217;t have to be rewritten for that.</p>
<p>The best example I found on this matter is Neal Gaffer&#8217;s one on his blog: <a href="http://gafter.blogspot.com/2007/03/closures-for-organizing-your-code.html" rel="nofollow">http://gafter.blogspot.com/2007/03/closures-for-organizing-your-code.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Howard Lovatt</title>
		<link>http://www.blog.dannynet.net/archives/87#comment-29391</link>
		<dc:creator>Howard Lovatt</dc:creator>
		<pubDate>Wed, 11 Apr 2007 22:52:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.blog.dannynet.net/archives/87#comment-29391</guid>
		<description>I have put a comparison of different inner class/closure proposals at:

http://www.artima.com/weblogs/viewpost.jsp?thread=202004</description>
		<content:encoded><![CDATA[<p>I have put a comparison of different inner class/closure proposals at:</p>
<p><a href="http://www.artima.com/weblogs/viewpost.jsp?thread=202004" rel="nofollow">http://www.artima.com/weblogs/viewpost.jsp?thread=202004</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Neal Gafter</title>
		<link>http://www.blog.dannynet.net/archives/87#comment-18063</link>
		<dc:creator>Neal Gafter</dc:creator>
		<pubDate>Mon, 05 Mar 2007 05:16:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.blog.dannynet.net/archives/87#comment-18063</guid>
		<description>If the precise same syntax is an expression and also a statement, then an extra semicolon would be needed to end the statement.  That sort of undermines the point of the control invocation syntax.</description>
		<content:encoded><![CDATA[<p>If the precise same syntax is an expression and also a statement, then an extra semicolon would be needed to end the statement.  That sort of undermines the point of the control invocation syntax.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Danny</title>
		<link>http://www.blog.dannynet.net/archives/87#comment-13971</link>
		<dc:creator>Danny</dc:creator>
		<pubDate>Wed, 07 Feb 2007 20:15:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.blog.dannynet.net/archives/87#comment-13971</guid>
		<description>@Neal: hmm... yes, I see... But why this limitation on the control invocation syntax? That means that for closures resulting in an expression, I'd have to write, for example:
&lt;pre class="code"&gt;
    Collection publishedBooks = select(books, {Book book =&gt;
        book.isPublished()
    });
&lt;/pre&gt;
...and for closures that do not need to result in an expression, I could choose between the standard and the control invocation form? Isn't that confusing? If you get used to the control invocation syntax, wouldn't you want to use it in all cases?</description>
		<content:encoded><![CDATA[<p>@Neal: hmm&#8230; yes, I see&#8230; But why this limitation on the control invocation syntax? That means that for closures resulting in an expression, I&#8217;d have to write, for example:</p>
<pre class="code">
    Collection publishedBooks = select(books, {Book book =>
        book.isPublished()
    });
</pre>
<p>&#8230;and for closures that do not need to result in an expression, I could choose between the standard and the control invocation form? Isn&#8217;t that confusing? If you get used to the control invocation syntax, wouldn&#8217;t you want to use it in all cases?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Neal Gafter</title>
		<link>http://www.blog.dannynet.net/archives/87#comment-13964</link>
		<dc:creator>Neal Gafter</dc:creator>
		<pubDate>Wed, 07 Feb 2007 18:15:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.blog.dannynet.net/archives/87#comment-13964</guid>
		<description>Also, you can't use wildcards as function argument types.</description>
		<content:encoded><![CDATA[<p>Also, you can&#8217;t use wildcards as function argument types.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nothing happens</title>
		<link>http://www.blog.dannynet.net/archives/87#comment-13957</link>
		<dc:creator>nothing happens</dc:creator>
		<pubDate>Wed, 07 Feb 2007 16:11:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.blog.dannynet.net/archives/87#comment-13957</guid>
		<description>[...] syntax for generics, it&#8217;s not too far off from C++&#8217;s it seems. But I went to look at these examples of how the new closures feature would look and I was lost. Apparently, Java has changed a lot since I last used it in college &#8212; a mere [...]</description>
		<content:encoded><![CDATA[<p>[...] syntax for generics, it&#8217;s not too far off from C++&#8217;s it seems. But I went to look at these examples of how the new closures feature would look and I was lost. Apparently, Java has changed a lot since I last used it in college &#8212; a mere [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Neal Gafter</title>
		<link>http://www.blog.dannynet.net/archives/87#comment-13954</link>
		<dc:creator>Neal Gafter</dc:creator>
		<pubDate>Wed, 07 Feb 2007 15:36:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.blog.dannynet.net/archives/87#comment-13954</guid>
		<description>The control invocation is a statement form, not an expression, and the controlled statement is a statement, not an expression.  I think none of your examples is syntactically correct.</description>
		<content:encoded><![CDATA[<p>The control invocation is a statement form, not an expression, and the controlled statement is a statement, not an expression.  I think none of your examples is syntactically correct.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
