<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Java Closures &#8211; The Fundamental Benefit</title>
	<atom:link href="http://warpedjavaguy.wordpress.com/2008/06/25/java-closures-the-fundamental-benefit/feed/" rel="self" type="application/rss+xml" />
	<link>http://warpedjavaguy.wordpress.com/2008/06/25/java-closures-the-fundamental-benefit/</link>
	<description>Observations of everyday Java phenomena</description>
	<lastBuildDate>Fri, 18 Dec 2009 05:32:07 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Howard Lovatt</title>
		<link>http://warpedjavaguy.wordpress.com/2008/06/25/java-closures-the-fundamental-benefit/#comment-326</link>
		<dc:creator>Howard Lovatt</dc:creator>
		<pubDate>Sun, 29 Jun 2008 00:16:39 +0000</pubDate>
		<guid isPermaLink="false">http://warpedjavaguy.wordpress.com/?p=32#comment-326</guid>
		<description>I think the different rules regarding different forms of returned can be overcome using named returns, as suggested in C3S. Neal Gafter has indicated in a reply to one of my blogs that he is considering named returns for BGGA. The idea of named returns is that return returns from the inner class/closure and if you want to return from the method enclosing the inner class.closure you say [methodName].return [value]opt;

The FCM proposal suggests that return returns from the closure except when the closure is used in a control structure, when it returns from the enclosing method.

I think that both named returns and the FCM proposal are superior to what is currently in BGGA, but as I said Neal is thinking of changing BGGA.

The C3S proposal adds no new semantics, it is just short syntax for inner classes. BGGA and FCM add a new construct the closure that is like an object but can&#039;t inherit, can&#039;t have fields, and its class has only one method. To get it to interact with objects it gets auto-boxed; but it can only be boxed into an interface with one method and once boxed there is no auto-unboxing. This autoboxing effectively introduces a second typing mechanism into Java, structural typing, thus complicating programs.

Personally I can see no advantage in the closure over the inner class, its less powerful than an object and needs auto-boxing and Java is an OO langage and I don&#039;t think we should go adding further non-objects (primitives already cause problems).</description>
		<content:encoded><![CDATA[<p>I think the different rules regarding different forms of returned can be overcome using named returns, as suggested in C3S. Neal Gafter has indicated in a reply to one of my blogs that he is considering named returns for BGGA. The idea of named returns is that return returns from the inner class/closure and if you want to return from the method enclosing the inner class.closure you say [methodName].return [value]opt;</p>
<p>The FCM proposal suggests that return returns from the closure except when the closure is used in a control structure, when it returns from the enclosing method.</p>
<p>I think that both named returns and the FCM proposal are superior to what is currently in BGGA, but as I said Neal is thinking of changing BGGA.</p>
<p>The C3S proposal adds no new semantics, it is just short syntax for inner classes. BGGA and FCM add a new construct the closure that is like an object but can&#8217;t inherit, can&#8217;t have fields, and its class has only one method. To get it to interact with objects it gets auto-boxed; but it can only be boxed into an interface with one method and once boxed there is no auto-unboxing. This autoboxing effectively introduces a second typing mechanism into Java, structural typing, thus complicating programs.</p>
<p>Personally I can see no advantage in the closure over the inner class, its less powerful than an object and needs auto-boxing and Java is an OO langage and I don&#8217;t think we should go adding further non-objects (primitives already cause problems).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: WarpedJavaGuy</title>
		<link>http://warpedjavaguy.wordpress.com/2008/06/25/java-closures-the-fundamental-benefit/#comment-325</link>
		<dc:creator>WarpedJavaGuy</dc:creator>
		<pubDate>Sat, 28 Jun 2008 02:35:45 +0000</pubDate>
		<guid isPermaLink="false">http://warpedjavaguy.wordpress.com/?p=32#comment-325</guid>
		<description>Stephen, yes the BGGA semicolon rule got me.

Clearly then what is most desirable is a closure solution that does not introduce odd behavior and change existing semantics.  Is CICE good enough?  Is BGGA too drastic?  Both C3S and BGGA change the semantics.  Does FCM strike the right balance?   

The debate over proposals will continue, but until we have closures in Java, the restructuring of code to eliminate redundancies will continue to result in unnecessary code which is itself redundant.</description>
		<content:encoded><![CDATA[<p>Stephen, yes the BGGA semicolon rule got me.</p>
<p>Clearly then what is most desirable is a closure solution that does not introduce odd behavior and change existing semantics.  Is CICE good enough?  Is BGGA too drastic?  Both C3S and BGGA change the semantics.  Does FCM strike the right balance?   </p>
<p>The debate over proposals will continue, but until we have closures in Java, the restructuring of code to eliminate redundancies will continue to result in unnecessary code which is itself redundant.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephen Colebourne</title>
		<link>http://warpedjavaguy.wordpress.com/2008/06/25/java-closures-the-fundamental-benefit/#comment-324</link>
		<dc:creator>Stephen Colebourne</dc:creator>
		<pubDate>Sat, 28 Jun 2008 00:27:04 +0000</pubDate>
		<guid isPermaLink="false">http://warpedjavaguy.wordpress.com/?p=32#comment-324</guid>
		<description>Your BGGA code example has a bug, and is the exact reason why BGGA closures are likely to be difficult to use in real coding. In case you haven&#039;t figured it out, the println requires a trailing semicolon. Why? Because run() from Runnable returns void. Last-line-no-semicolon return only works if there is a non-void return type. And thats the kind of confusing set of rules we can do without in Java.
(Disclaimer - I&#039;m co-author of FCM closures)</description>
		<content:encoded><![CDATA[<p>Your BGGA code example has a bug, and is the exact reason why BGGA closures are likely to be difficult to use in real coding. In case you haven&#8217;t figured it out, the println requires a trailing semicolon. Why? Because run() from Runnable returns void. Last-line-no-semicolon return only works if there is a non-void return type. And thats the kind of confusing set of rules we can do without in Java.<br />
(Disclaimer &#8211; I&#8217;m co-author of FCM closures)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Howard Lovatt</title>
		<link>http://warpedjavaguy.wordpress.com/2008/06/25/java-closures-the-fundamental-benefit/#comment-323</link>
		<dc:creator>Howard Lovatt</dc:creator>
		<pubDate>Sat, 28 Jun 2008 00:25:16 +0000</pubDate>
		<guid isPermaLink="false">http://warpedjavaguy.wordpress.com/?p=32#comment-323</guid>
		<description>I am with Mikael. CICE, BGGA, C3S (http://www.artima.com/weblogs/viewpost.jsp?thread=182412), and FCM all give shorter syntax and write to local variables. The examples you have given only show that shorter syntax would be nice. There are serious drawbacks with closures (BGGA and FCM), they introduce a second typing system, they are like an object but not quite, and the meaning of return is changed. To allow the closures &#039;to play&#039; with normal objects they get boxed, but there is no unboxing. This leads to strange behaviour, similar to the strange behaviour when primitives get boxed. Further, because there is no unboxing, other odd behaviour happens. Also closures cannot inherit and can only be boxed into interfaces, not classes. Java is first and foremost an OO language, lets keep it that way and not introduce something else that is not an object and requires boxing.</description>
		<content:encoded><![CDATA[<p>I am with Mikael. CICE, BGGA, C3S (<a href="http://www.artima.com/weblogs/viewpost.jsp?thread=182412" rel="nofollow">http://www.artima.com/weblogs/viewpost.jsp?thread=182412</a>), and FCM all give shorter syntax and write to local variables. The examples you have given only show that shorter syntax would be nice. There are serious drawbacks with closures (BGGA and FCM), they introduce a second typing system, they are like an object but not quite, and the meaning of return is changed. To allow the closures &#8216;to play&#8217; with normal objects they get boxed, but there is no unboxing. This leads to strange behaviour, similar to the strange behaviour when primitives get boxed. Further, because there is no unboxing, other odd behaviour happens. Also closures cannot inherit and can only be boxed into interfaces, not classes. Java is first and foremost an OO language, lets keep it that way and not introduce something else that is not an object and requires boxing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: WarpedJavaGuy</title>
		<link>http://warpedjavaguy.wordpress.com/2008/06/25/java-closures-the-fundamental-benefit/#comment-322</link>
		<dc:creator>WarpedJavaGuy</dc:creator>
		<pubDate>Thu, 26 Jun 2008 23:46:11 +0000</pubDate>
		<guid isPermaLink="false">http://warpedjavaguy.wordpress.com/?p=32#comment-322</guid>
		<description>What Howard wrote was &quot;Inner classes with short syntax and write ability to local variables do all this and more&quot;.  This is simply not true.  The reason CICE makes sense is because it eliminates the boilerplate associated with anonymous inner classes.

My point in this post is to highlight the primary benefit that closures bring to the Java language.  They introduce to Java a language construct that eliminates boilerplate and removes unnecessary redundancy.</description>
		<content:encoded><![CDATA[<p>What Howard wrote was &#8220;Inner classes with short syntax and write ability to local variables do all this and more&#8221;.  This is simply not true.  The reason CICE makes sense is because it eliminates the boilerplate associated with anonymous inner classes.</p>
<p>My point in this post is to highlight the primary benefit that closures bring to the Java language.  They introduce to Java a language construct that eliminates boilerplate and removes unnecessary redundancy.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mikael Grev</title>
		<link>http://warpedjavaguy.wordpress.com/2008/06/25/java-closures-the-fundamental-benefit/#comment-321</link>
		<dc:creator>Mikael Grev</dc:creator>
		<pubDate>Thu, 26 Jun 2008 21:25:33 +0000</pubDate>
		<guid isPermaLink="false">http://warpedjavaguy.wordpress.com/?p=32#comment-321</guid>
		<description>You did not read what Howard wrote... He said &quot;Inner classes with short syntax&quot;. Like with CICE, the only closures proposal that makes sense this late in the Java cycle.</description>
		<content:encoded><![CDATA[<p>You did not read what Howard wrote&#8230; He said &#8220;Inner classes with short syntax&#8221;. Like with CICE, the only closures proposal that makes sense this late in the Java cycle.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: WarpedJavaGuy</title>
		<link>http://warpedjavaguy.wordpress.com/2008/06/25/java-closures-the-fundamental-benefit/#comment-320</link>
		<dc:creator>WarpedJavaGuy</dc:creator>
		<pubDate>Thu, 26 Jun 2008 10:22:01 +0000</pubDate>
		<guid isPermaLink="false">http://warpedjavaguy.wordpress.com/?p=32#comment-320</guid>
		<description>You cannot in the current Java language write anonymous inner classes without also writing boilerplate code.  This is a necessary redundancy that cannot be eliminated.

For example, the code snippet below contains boilerplate that is redundant and that you should not have to write.

&lt;code&gt;new Thread(new Runnable() { 
&#160; public void run() { 
&#160; &#160; System.out.println(&quot;Anonymous Inner Class&quot;); 
&#160; } 
}).start();&lt;/code&gt;

..whereas closures eliminate the redundant boilerplate required above:

&lt;code&gt;new Thread({ =&gt; 
&#160; System.out.println(&quot;Closure&quot;) 
}).start();&lt;/code&gt;

As an aside, inner classes are a poor man&#039;s closure because 
they do not capture the enclosing environment in its entirety (that is: they do not capture variable names, the &#039;this&#039; object, the referents of break, continue, return, etc..).  Inner classes are definitely not closures.  See &lt;a href=&quot;http://gafter.blogspot.com/2007/01/definition-of-closures.html&quot; rel=&quot;nofollow&quot;&gt;closure definition&lt;/a&gt;.</description>
		<content:encoded><![CDATA[<p>You cannot in the current Java language write anonymous inner classes without also writing boilerplate code.  This is a necessary redundancy that cannot be eliminated.</p>
<p>For example, the code snippet below contains boilerplate that is redundant and that you should not have to write.</p>
<p><code>new Thread(new Runnable() {<br />
&nbsp; public void run() {<br />
&nbsp; &nbsp; System.out.println("Anonymous Inner Class");<br />
&nbsp; }<br />
}).start();</code></p>
<p>..whereas closures eliminate the redundant boilerplate required above:</p>
<p><code>new Thread({ =&gt;<br />
&nbsp; System.out.println("Closure")<br />
}).start();</code></p>
<p>As an aside, inner classes are a poor man&#8217;s closure because<br />
they do not capture the enclosing environment in its entirety (that is: they do not capture variable names, the &#8216;this&#8217; object, the referents of break, continue, return, etc..).  Inner classes are definitely not closures.  See <a href="http://gafter.blogspot.com/2007/01/definition-of-closures.html" rel="nofollow">closure definition</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Howard Lovatt</title>
		<link>http://warpedjavaguy.wordpress.com/2008/06/25/java-closures-the-fundamental-benefit/#comment-319</link>
		<dc:creator>Howard Lovatt</dc:creator>
		<pubDate>Thu, 26 Jun 2008 07:53:08 +0000</pubDate>
		<guid isPermaLink="false">http://warpedjavaguy.wordpress.com/?p=32#comment-319</guid>
		<description>Inner classes with short syntax and write ability to local variables do all this and more. Closures are a poor man&#039;s inner class, see URL.</description>
		<content:encoded><![CDATA[<p>Inner classes with short syntax and write ability to local variables do all this and more. Closures are a poor man&#8217;s inner class, see URL.</p>
]]></content:encoded>
	</item>
</channel>
</rss>