<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	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>warpedjavaguy</title>
	<atom:link href="http://warpedjavaguy.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://warpedjavaguy.wordpress.com</link>
	<description>Observations of everyday programming phenomena</description>
	<lastBuildDate>Wed, 28 Dec 2011 21:25:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='warpedjavaguy.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/05f7833c15b4a747643fabb0f037564e?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>warpedjavaguy</title>
		<link>http://warpedjavaguy.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://warpedjavaguy.wordpress.com/osd.xml" title="warpedjavaguy" />
	<atom:link rel='hub' href='http://warpedjavaguy.wordpress.com/?pushpress=hub'/>
		<item>
		<title>How I defeated the maven-release-plugin in a flat structured multi module project</title>
		<link>http://warpedjavaguy.wordpress.com/2011/08/08/how-i-defeated-the-maven-release-plugin-in-a-flat-structured-multi-module-project/</link>
		<comments>http://warpedjavaguy.wordpress.com/2011/08/08/how-i-defeated-the-maven-release-plugin-in-a-flat-structured-multi-module-project/#comments</comments>
		<pubDate>Mon, 08 Aug 2011 13:21:15 +0000</pubDate>
		<dc:creator>warpedjavaguy</dc:creator>
				<category><![CDATA[automation]]></category>
		<category><![CDATA[maven]]></category>

		<guid isPermaLink="false">http://warpedjavaguy.wordpress.com/?p=390</guid>
		<description><![CDATA[Rules are made to be broken so that paradoxes can be created. Maven is a handy tool and has a lot of available plugins. It adopts the convention over configuration philosophy and provides a standard build lifecycle out of the box. This makes it very easy to automate a build and release process without writing [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=warpedjavaguy.wordpress.com&amp;blog=809469&amp;post=390&amp;subd=warpedjavaguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p><em>Rules are made to be broken so that paradoxes can be created.</em></p></blockquote>
<p><a href="http://maven.apache.org/">Maven</a> is a handy tool and has a lot of available plugins.  It adopts the convention over configuration philosophy and provides a standard build lifecycle out of the box.  This makes it very easy to automate a build and release process without writing a single line of script.  But there&#8217;s a catch!  It only works if you do things the &#8220;maven way&#8221; and follow the maven rules.</p>
<p>Most projects are made up of one or more multiple smaller projects.  In the maven world, such projects are called multi module projects.  A multi module project has a parent project and one or more nested child projects known as modules.  When you build the parent project the child projects are also built.  The recommended maven way of structuring a multi module project is to mirror the parent child hierarchy using a nested project structure.  </p>
<p>So maven recommends that you create a parent project that contains the child projects using a physical project structure like this:</p>
<p><pre class="brush: plain;">
workspace/parent/pom.xml
workspace/parent/child1/pom.xml
workspace/parent/child2/pom.xml
</pre></p>
<p>Modules are then declared in the parent POM like this:</p>
<p><pre class="brush: xml;">
&lt;modules&gt;
  &lt;module&gt;child1&lt;/module&gt;
  &lt;module&gt;child2&lt;/module&gt;
&lt;/modules&gt;
</pre></p>
<p>This was good for maven but it was is not good for eclipse.  The eclipse IDE does not support nested projects.  This was clearly a problem!  I wanted to import all my projects (parent and children) into eclipse but the nested structure made this impossible.  So I decided to use a flat project structure instead and moved all my child projects out of the parent project.</p>
<p>Now my parent and child projects were organised in a flat physical structure like this:</p>
<p><pre class="brush: plain;">
workspace/parent/pom.xml
workspace/child1/pom.xml
workspace/child2/pom.xml
</pre></p>
<p>And I then redefined the maven modules in the parent POM like this:</p>
<p><pre class="brush: xml;">
&lt;modules&gt;
  &lt;module&gt;../child1&lt;/module&gt;
  &lt;module&gt;../child2&lt;/module&gt;
&lt;/modules&gt;
</pre>  </p>
<p>Now I could import all my projects into eclipse.  This worked well and life was good until I decided to use the <a href="http://maven.apache.org/plugins/maven-release-plugin/">maven release plugin</a> to automate the release process.  I learned the hard way that the release plugin only supports the nested project structure recommended by maven.  Reverting back to the nested structure was not an option.  I had broken a maven rule and was being punished for it!  I needed a paradoxical solution that would support both the nested and flat structures at the same time.  It was then that I realised that my parent POM was responsible for two things: POM inheritance and module composition.  It served two &#8220;parental&#8221; roles.  In one role it provided all the common properties, dependencies, plugins, and profiles to all children through inheritance and in the other it defined itself as the parent project of all child projects.  In OO terms, this was akin to defining a superclass that contains a list of all its subclasess.</p>
<p>My parent POM had violated the single responsibility principle. So I decided to split it up into two separate parent POMs.  I removed the modules declaration from the original POM in my parent project.  This POM was now purely to be used for inheritance purposes only.  All child POMs continued to reference this POM as the parent POM.  Nothing changed there.  I then created a new POM that inherited this modified POM and aggregated all the other child POMs.  I placed this new top level POM file in the workspace root alongside all my existing projects.  My flat project structure now had a top level POM file that defined all the child projects as modules.  </p>
<p>The final project structure looked like this:</p>
<p><pre class="brush: plain;">
workspace/pom.xml
workspace/parent/pom.xml
workspace/child1/pom.xml
workspace/child2/pom.xml
</pre></p>
<p>The <code>workspace/parent/pom.xml</code> was inherited by all child POMs and also the top level <code>workspace/pom.xml</code>. It was the parent POM for inheritance purposes.  The top level <code>workspace/pom.xml</code> aggregated all the child projects into one container project.  It was the (root) parent POM for composition purposes. It defined the parent and child modules like this:</p>
<p><pre class="brush: xml;">
&lt;parent&gt;
  &lt;groupId&gt;?&lt;/groupId&gt;
  &lt;artifactId&gt;?&lt;/artifactId&gt;
  &lt;version&gt;?&lt;/version&gt;
  &lt;relativePath&gt;parent/pom.xml&lt;/relativePath&gt;
&lt;/parent&gt;
&lt;modules&gt;
  &lt;module&gt;parent&lt;/module&gt;
  &lt;module&gt;child1&lt;/module&gt;
  &lt;module&gt;child2&lt;/module&gt;
&lt;/modules&gt;
</pre></p>
<p>Both the maven release plugin and the eclipse IDE were happy with this structure.  It was flat enough for eclipse and hierarchical enough for the maven release plugin.</p>
<p><i>Note: After experiencing and resolving this problem first hand I later discovered that the issue has already been <a href="http://jira.codehaus.org/browse/MRELEASE-261">reported and discussed here</a> and mentioned at the very bottom of the <a href="http://maven.apache.org/plugins/maven-eclipse-plugin/reactor.html">maven eclipse plugin</a> page.  But I still cannot find any mention of this limitation on the <a href="http://maven.apache.org/plugins/maven-release-plugin/index.html">maven release plugin</a> page itself.  I suspect that this is a well known issue in the maven community.  If anyone is aware of any fixes or better solutions, please let me know.  Interestingly also the title of <a href="http://jira.codehaus.org/browse/MECLIPSE-520">this issue</a> suggests that the problem has been fixed but the actual contents therein state otherwise.</i></p>
<p><b>Sample POM snippets</b> &#8211; Posted on 22 Aug 2011 by <a href="http://warpedjavaguy.wordpress.com/2011/08/08/how-i-defeated-the-maven-release-plugin-in-a-flat-structured-multi-module-project/#comment-505">request</a></p>
<p><code>workspace/pom.xml</code> (The top level root POM)<br />
<pre class="brush: xml; collapse: true; light: false; toolbar: true;">
  &lt;parent&gt; 
    &lt;groupId&gt;maven.demo&lt;/groupId&gt; 
    &lt;artifactId&gt;parent&lt;/artifactId&gt; 
    &lt;version&gt;1.0.0-SNAPSHOT&lt;/version&gt;
    &lt;relativePath&gt;parent/pom.xml&lt;/relativePath&gt;
  &lt;/parent&gt; 

  &lt;groupId&gt;maven.demo&lt;/groupId&gt;
  &lt;artifactId&gt;root&lt;/artifactId&gt;
  &lt;version&gt;1.0.0-SNAPSHOT&lt;/version&gt;
  &lt;packaging&gt;pom&lt;/packaging&gt;

  &lt;modules&gt;
    &lt;module&gt;parent&lt;/module&gt;
    &lt;module&gt;child1&lt;/module&gt;
    &lt;module&gt;child2&lt;/module&gt;
  &lt;/modules&gt;
</pre></p>
<p><code>workspace/parent/pom.xml</code> (The parent POM)<br />
<pre class="brush: xml; collapse: true; light: false; toolbar: true;">
  &lt;groupId&gt;maven.demo&lt;/groupId&gt;
  &lt;artifactId&gt;parent&lt;/artifactId&gt;
  &lt;version&gt;1.0.0-SNAPSHOT&lt;/version&gt;
  &lt;packaging&gt;pom&lt;/packaging&gt;
</pre></p>
<p><code>workspace/child1/pom.xml</code> (The child1 POM)<br />
<pre class="brush: xml; collapse: true; light: false; toolbar: true;">
  &lt;parent&gt; 
    &lt;groupId&gt;maven.demo&lt;/groupId&gt; 
    &lt;artifactId&gt;parent&lt;/artifactId&gt; 
    &lt;version&gt;1.0.0-SNAPSHOT&lt;/version&gt;
    &lt;relativePath&gt;../parent/pom.xml&lt;/relativePath&gt;
  &lt;/parent&gt; 

  &lt;groupId&gt;maven.demo&lt;/groupId&gt;
  &lt;artifactId&gt;child1&lt;/artifactId&gt;
  &lt;version&gt;1.0.0-SNAPSHOT&lt;/version&gt;
  &lt;packaging&gt;jar&lt;/packaging&gt;
</pre></p>
<p><code>workspace/child2/pom.xml</code> (The child2 POM)<br />
<pre class="brush: xml; collapse: true; light: false; toolbar: true;">
  &lt;parent&gt; 
    &lt;groupId&gt;maven.demo&lt;/groupId&gt; 
    &lt;artifactId&gt;parent&lt;/artifactId&gt; 
    &lt;version&gt;1.0.0-SNAPSHOT&lt;/version&gt;
    &lt;relativePath&gt;../parent/pom.xml&lt;/relativePath&gt;
  &lt;/parent&gt; 

  &lt;groupId&gt;maven.demo&lt;/groupId&gt;  
  &lt;artifactId&gt;child2&lt;/artifactId&gt;
  &lt;version&gt;1.0.0-SNAPSHOT&lt;/version&gt;
  &lt;packaging&gt;war&lt;/packaging&gt;
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/warpedjavaguy.wordpress.com/390/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/warpedjavaguy.wordpress.com/390/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/warpedjavaguy.wordpress.com/390/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/warpedjavaguy.wordpress.com/390/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/warpedjavaguy.wordpress.com/390/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/warpedjavaguy.wordpress.com/390/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/warpedjavaguy.wordpress.com/390/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/warpedjavaguy.wordpress.com/390/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/warpedjavaguy.wordpress.com/390/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/warpedjavaguy.wordpress.com/390/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/warpedjavaguy.wordpress.com/390/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/warpedjavaguy.wordpress.com/390/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/warpedjavaguy.wordpress.com/390/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/warpedjavaguy.wordpress.com/390/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=warpedjavaguy.wordpress.com&amp;blog=809469&amp;post=390&amp;subd=warpedjavaguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://warpedjavaguy.wordpress.com/2011/08/08/how-i-defeated-the-maven-release-plugin-in-a-flat-structured-multi-module-project/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b5c8e528c21ff5b742756afdef7a9219?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif" medium="image">
			<media:title type="html">WarpedJavaGuy</media:title>
		</media:content>
	</item>
		<item>
		<title>Hey Null, Don&#8217;t Touch My Monads!</title>
		<link>http://warpedjavaguy.wordpress.com/2011/06/08/hey-null-dont-touch-my-monads/</link>
		<comments>http://warpedjavaguy.wordpress.com/2011/06/08/hey-null-dont-touch-my-monads/#comments</comments>
		<pubDate>Tue, 07 Jun 2011 18:35:38 +0000</pubDate>
		<dc:creator>warpedjavaguy</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://warpedjavaguy.wordpress.com/?p=363</guid>
		<description><![CDATA[Null handling.. we&#8217;ve been doing it completely wrong! Nulls are a big problem! They are a most constant annoyance and the single root cause of all NullPointerExceptions. It is common practice in Java to defensively check for nulls everywhere. It would be nice if they could just go away. But they won&#8217;t because we&#8217;ve been [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=warpedjavaguy.wordpress.com&amp;blog=809469&amp;post=363&amp;subd=warpedjavaguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p><em><br />
Null handling.. we&#8217;ve been doing it completely wrong!</em></p>
</blockquote>
<p>Nulls are a big problem!  They are a most constant annoyance and the single root cause of all NullPointerExceptions.  It is common practice in Java to defensively check for nulls everywhere.  It would be nice if they could just go away.  But they won&#8217;t because we&#8217;ve been using them on purpose to denote missing values.  Almost every Java API uses nulls in this way.  </p>
<p>When we integrate with Java API&#8217;s we have to check for nulls.  Fortunately, Scala provides the <a href="http://www.scala-lang.org/api/current/scala/Option.html">Option monad</a> to help deal with nulls.  It is basically a container that can hold two types of values; Some or None (some value or no value).  But for Java interoperability purposes, Some can also hold null.  Is this a problem?  Lets explore..</p>
<p>First, we&#8217;ll define a User class like this (overly simple I know)<br />
<pre class="brush: scala;">
case class User (name: String)
</pre></p>
<p>Now we&#8217;ll define a list of users and filter it<br />
<pre class="brush: scala;">
val users = List(User(&quot;Wendy&quot;), User(&quot;Bob&quot;))
users filter { _.name == &quot;Bob&quot; }
</pre></p>
<p>This yields List(User(Bob)).  So far so good!  Now lets redefine the user list by including a null entry.<br />
<pre class="brush: scala;">
val users = List(User(&quot;Wendy&quot;), null, User(&quot;Bob&quot;))
users filter { _.name == &quot;Bob&quot; }
</pre></p>
<p>Bang! NullPointerException!  Lets fix it by checking for null.<br />
<pre class="brush: scala;">
users filter { u =&gt; u != null &amp;&amp; u.name == &quot;Bob&quot; }
</pre></p>
<p>This yields List(User(Bob)) again.  Good, but this is ugly.  We don&#8217;t want to check for nulls.  Let&#8217;s wrap every element in an Option instance.<br />
<pre class="brush: scala;">
users flatMap { Option(_) } filter { _.name == &quot;Bob&quot; }
</pre></p>
<p>Option(null) resolves to None and the expression yields List(User(Bob)) again.  Nice!  Now let&#8217;s try and wrap every element in a Some instance instead and see what happens.<br />
<pre class="brush: scala;">
users flatMap { Some(_) } filter { _.name == &quot;Bob&quot; }
</pre></p>
<p>Some(null) resolves to null and oh no, we get a NullPointerException!  This is a problem.  We want Some(null) to resolve to None. So lets define our own Some function that overrides this behavior.<br />
<pre class="brush: scala;">
def Some[T](x: T) = Option(x)
users flatMap { Some(_) } filter { _.name == &quot;Bob&quot; }
</pre></p>
<p>Now Some(null) returns Option(null) which resolves to None and the expression yields List(User(Bob)) as expected.  Ok, so we&#8217;ve solved the Some(null) problem.  Now lets look at another null problem. Lets blindly extract the second user element in the list (the null entry) and print the name property.<br />
<pre class="brush: scala;">
val user = users(1)
println(user.name)
</pre></p>
<p>The user reference is null and we get a NullPointerException.  Oh dread, we didn&#8217;t check for null.  Let&#8217;s do that.<br />
<pre class="brush: scala;">
if (user != null) {
  println(user.name)
}
</pre></p>
<p>Now we skip the printing of the name if the reference is null.  But we don&#8217;t want to check for nulls.  So lets wrap the null user in an Option and use foreach.<br />
<pre class="brush: scala;">
Option(user) foreach { u =&gt; println(u.name) }
</pre></p>
<p>Option(null) resolves to None and all is good.  With our overriding Some function still in scope, we can do the same using Some also.<br />
<pre class="brush: scala;">
Some(user) foreach { u =&gt; println(u.name) }
</pre></p>
<p>Just like before, our call to Some(null) returns Option(null) which resolves to None and we&#8217;re good.  But we want cleaner code that looks like this:<br />
<pre class="brush: scala;">
user foreach { u =&gt; println(u.name) }
</pre></p>
<p>This results in a compile error because foreach is not a member of User.  But we can fix that by making our overriding Some function implicit.  With this implicit in scope, Scala converts user to Option(user) and the above will now work.<br />
<pre class="brush: scala;">
implicit def Some[T](x: T) = Option(x)
user foreach { u =&gt; println(u.name) }
</pre></p>
<p>Taking this a step further, we can map the user name and print it like this.  If the user is null, the name is never mapped and never printed.<br />
<pre class="brush: scala;">
user map { _.name } foreach println
</pre></p>
<p>Nulls be gone! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Now of course there are many cases in Java where nulls are legitimate values, and for this reason Scala supports Some(null) = null.  But as shown above, that doesn&#8217;t mean we can&#8217;t override that with Some(null) = None.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/warpedjavaguy.wordpress.com/363/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/warpedjavaguy.wordpress.com/363/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/warpedjavaguy.wordpress.com/363/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/warpedjavaguy.wordpress.com/363/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/warpedjavaguy.wordpress.com/363/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/warpedjavaguy.wordpress.com/363/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/warpedjavaguy.wordpress.com/363/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/warpedjavaguy.wordpress.com/363/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/warpedjavaguy.wordpress.com/363/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/warpedjavaguy.wordpress.com/363/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/warpedjavaguy.wordpress.com/363/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/warpedjavaguy.wordpress.com/363/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/warpedjavaguy.wordpress.com/363/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/warpedjavaguy.wordpress.com/363/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=warpedjavaguy.wordpress.com&amp;blog=809469&amp;post=363&amp;subd=warpedjavaguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://warpedjavaguy.wordpress.com/2011/06/08/hey-null-dont-touch-my-monads/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b5c8e528c21ff5b742756afdef7a9219?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif" medium="image">
			<media:title type="html">WarpedJavaGuy</media:title>
		</media:content>
	</item>
		<item>
		<title>The &#8220;Scala is too Complex&#8221; Conspiracy</title>
		<link>http://warpedjavaguy.wordpress.com/2010/08/02/the-scala-is-too-complex-conspiracy-1/</link>
		<comments>http://warpedjavaguy.wordpress.com/2010/08/02/the-scala-is-too-complex-conspiracy-1/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 13:14:57 +0000</pubDate>
		<dc:creator>warpedjavaguy</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://warpedjavaguy.wordpress.com/?p=282</guid>
		<description><![CDATA[They don&#8217;t want pragmatic Scala programmers. &#160; The &#8220;Scala is too complex for the average programmer&#8221; movement is disturbing. It conspires that Scala is too difficult for the average programmer to learn and that it is too academic. Scala is a hybrid programming language that is object oriented and functional. Java is a programming language [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=warpedjavaguy.wordpress.com&amp;blog=809469&amp;post=282&amp;subd=warpedjavaguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p><em><br />
They don&#8217;t want pragmatic Scala programmers.</em><br />
&nbsp;
</p></blockquote>
<p>The &#8220;Scala is too complex for the average programmer&#8221; movement is disturbing.  It conspires that Scala is too difficult for the average programmer to learn and that it is too academic.  Scala is a hybrid programming language that is object oriented and functional.  Java is a programming language that is object oriented and imperative.  This means that Java programmers have no functional programming power.</p>
<p>This year I read <a href="http://www.artima.com/shop/programming_in_scala">Programming in Scala</a> and practiced some functional programming.  I converted some Java code I had lying around to Scala and gained some hands on experience with case classes, pattern matching, lazy evaluation, implicit conversions, lambdas, and closures.  I also reduced and folded lists and wrote curried functions.  I was pleasantly shocked and surprised!</p>
<p>It is true that moving from object oriented to functional programming requires a shift in mindset.  It is true also that many Java programmers are already thinking functionally but are unaware of it.  In Java we use immutable objects when programming for concurrency.  We use anonymous inner classes to simulate lambdas and closures.  We use iterators and predicates to simulate list comprehensions.  We recognize these and other functional concepts but implement them in roundabout ways because there is no direct support for them in the Java language. </p>
<p>Fortunately Java 7 is looking to add <a href="http://openjdk.java.net/projects/lambda/">lambda</a> support to the language so we will soon no longer have to write anonymous inner classes wherever single method interfaces and abstract classes (SAM types) are expected.   In the meantime Scala has emerged as a functional language that Java programmers can learn and transition to without sacrificing their object oriented skills and without leaving the JVM platform.</p>
<p>For any programmer who has not looked at Scala or who has been deterred by a &#8220;too complex&#8221; conspirator, here are some code samples..</p>
<h3>Case classes</h3>
<p>Lets create a class named Path that accepts a source and destination city as two separate characters and exposes them as public read only properties.<br />
<pre class="brush: scala;">
case class Path (origin: Char, destination: Char)
</pre><br />
Prefixing a class definition with the &#8220;case&#8221; keyword automatically exposes constructor arguments as public read only properties.  It also adds a factory method to your class so you don&#8217;t have to instantiate it with new, so Path(&#8216;A&#8217;, &#8216;B&#8217;) will suffice for example.  It also provides a toString method that returns a string literal like Path(A,B).  You also get a natural implementation of the hashCode and equals methods.  You get constructor pattern matching support too.  All this for free with a one liner case class.</p>
<h3>Factory method with pattern matching</h3>
<p>Now lets create a factory method that accepts a string, parses it, and returns a Path instance.  For example, passing the string &#8220;AB&#8221; should return a Path(&#8216;A&#8217;, &#8216;B&#8217;) instance whereas passing the string &#8220;ABC&#8221; should fail.<br />
<pre class="brush: scala;">
object Path {	
  val PathRE = &quot;^([A-Z]{1})([A-Z]{1})$&quot;.r
  def apply(pathStr: String): Path = pathStr match {
      case PathRE(origin, destination) 
      	=&gt; Path(origin(0), destination(0))
      case _ 
      	=&gt; throw new IllegalArgumentException(pathStr)
  }
}
</pre><br />
Now we can instantiate a Path as Path(&#8220;AB&#8221;) in addition to Path(&#8216;A&#8217;, &#8216;B&#8217;). Any string that does not contain exactly two characters that are not between A and Z will result in an IllegalArgumentException.  So the strings &#8220;a&#8221;, &#8220;1&#8243;, &#8220;A1&#8243;, and &#8220;ABC&#8221; will all fail construction.  As a safeguard we can add an assert statement to the Path constructor to ensure that the source and destination cities are never equal like this:<br />
<pre class="brush: scala;">
case class Path (origin: Char, destination: Char) {
  assert (origin != destination, &quot;origin and destination are same&quot;)
}
</pre></p>
<h3>Implicit conversion</h3>
<p>Now lets make it possible to assign the string literal &#8220;AB&#8221; directly to any Path type anywhere so that we don&#8217;t have to call the factory method explicitly.  We do this by prefixing our apply(String) factory method with the keyword implicit as shown below:<br />
<pre class="brush: scala;">
implicit def apply(pathStr: String): Path
</pre><br />
Now the string literal &#8220;AB&#8221; can be accepted anywhere where a Path instance is expected.</p>
<h3>Folding Lists</h3>
<p>Now suppose we want to write an application that accepts a list of Path string literals from the command line.  We can convert the incoming list of Path strings to a Set of Path instances by using a fold left operation.  The following creates a new empty Set and adds to it every Path in the incoming list.  Each string in the list is automatically converted to a Path instance through implicit conversion.<br />
<pre class="brush: scala;">
def main(args: Array[String]) {
  val pathSet = (Set[Path]() /: args) (_+_)
}
</pre></p>
<h3>Lambda expressions</h3>
<p>Now lets say we have already written a function named find, that finds all the routes from one city to another based on some route condition.  This function accepts two arguments, a Path containing the from and to cities, and a predicate lambda expression.  The signature looks like this:<br />
<pre class="brush: scala;">
def find(path: Path, predicate: Route =&gt; Boolean): List[Route]
</pre><br />
We can invoke this function to find (for example) all the routes from city &#8216;A&#8217; to city &#8216;E&#8217; having less than 3 stops like this:<br />
<pre class="brush: scala;">
val routes = find(&quot;AE&quot;, route =&gt; route.stops &lt; 3)
</pre></p>
<h3>Currying</h3>
<p>We can curry the find function by splitting its two argument parameter list into two one argument parameter lists like this:<br />
<pre class="brush: scala;">
def find(path: Path)(predicate: Route =&gt; Boolean): List[Route]
</pre><br />
Now when we invoke the find function with a Path argument we get a second function that we can then invoke with the predicate argument to get the result.  We can invoke our curried function like this:<br />
<pre class="brush: scala;">
val routes = find(&quot;AE&quot;)(route =&gt; route.stops &lt; 3)
</pre><br />
Scala allows us to optionally wrap the sole argument to a single argument function in curly braces instead of parenthesis. So we can also invoke our curried function like this:<br />
<pre class="brush: scala;">
val routes = find(&quot;AE&quot;) { route =&gt; route.stops &lt; 3 }
</pre><br />
Now our call to the find function looks like a built in Scala construct.</p>
<h3>Is Scala too Complex?</h3>
<p>If you think that the above Scala code is too complex then I urge you to try and achieve the same in Java with less complexity.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/warpedjavaguy.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/warpedjavaguy.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/warpedjavaguy.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/warpedjavaguy.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/warpedjavaguy.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/warpedjavaguy.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/warpedjavaguy.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/warpedjavaguy.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/warpedjavaguy.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/warpedjavaguy.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/warpedjavaguy.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/warpedjavaguy.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/warpedjavaguy.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/warpedjavaguy.wordpress.com/282/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=warpedjavaguy.wordpress.com&amp;blog=809469&amp;post=282&amp;subd=warpedjavaguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://warpedjavaguy.wordpress.com/2010/08/02/the-scala-is-too-complex-conspiracy-1/feed/</wfw:commentRss>
		<slash:comments>82</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b5c8e528c21ff5b742756afdef7a9219?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif" medium="image">
			<media:title type="html">WarpedJavaGuy</media:title>
		</media:content>
	</item>
		<item>
		<title>Implicitly Formatted Exceptions</title>
		<link>http://warpedjavaguy.wordpress.com/2008/09/16/implicitly-formatted-exceptions/</link>
		<comments>http://warpedjavaguy.wordpress.com/2008/09/16/implicitly-formatted-exceptions/#comments</comments>
		<pubDate>Tue, 16 Sep 2008 12:56:31 +0000</pubDate>
		<dc:creator>warpedjavaguy</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[exceptions]]></category>

		<guid isPermaLink="false">http://warpedjavaguy.wordpress.com/?p=110</guid>
		<description><![CDATA[It takes a lot of ugly code to create beautiful exception messages. &#160; In Java, we write code that throws and catches exceptions a lot. The core Java exception classes provide the following two constructors for instantiating exceptions with messages: public Throwable(String message) public Throwable(String message, Throwable cause) Creating nicely formatted and meaningful exception messages [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=warpedjavaguy.wordpress.com&amp;blog=809469&amp;post=110&amp;subd=warpedjavaguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p><em><br />
It takes a lot of ugly code to create beautiful exception messages.</em><br />
&nbsp;<br />
<em></em></p></blockquote>
<p>In Java, we write code that throws and catches exceptions a lot.  The core Java exception classes provide the following two constructors for instantiating exceptions with messages:</p>
<p><code>public Throwable(String message)</code><br />
<code>public Throwable(String message, Throwable cause)</code></p>
<p>Creating nicely formatted and meaningful exception messages using these two constructors is more difficult than it should be and often involves a lot of concatenations of plain text and formatted data.  These concatenated string conglomerations are so tedious to write that they deter us from good message formatting practices (let alone proper grammatical correctness).  When we do put in the extra effort to get our exception messages right, our code suddenly becomes ugly and loses its elegance.</p>
<p>The <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat</a> class would help a lot in this regard.  Using it explicitly to create exception messages can make life a little easier, but I often find myself extending exceptions to use it implicitly like this:</p>
<pre><pre class="brush: java;">
import java.text.MessageFormat;

public class MyException extends Exception {

public MyException(String pattern, Object... args) {
super(MessageFormat.format(pattern, args));
}

public MyException(Exception cause, String pattern, Object... args) {
super(MessageFormat.format(pattern, args), cause);
}
}
</pre></pre>
<p>Wouldn&#8217;t it be nice if all Java exceptions had these additional constructors?</p>
<p><code>public Throwable(String pattern, Object... args)</code><br />
<code>public Throwable(Throwable cause, String pattern, Object... args)</code><br />
<!-- AddThis Bookmark Button BEGIN --><a title="Bookmark using any bookmark manager!" href="http://www.addthis.com/bookmark.php?url=http://warpedjavaguy.wordpress.com/2008/09/16/implicitly-formatted-exceptions/" target="_blank"><img src="http://s9.addthis.com/button1-bm.gif" border="0" alt="AddThis Social Bookmark Button" width="125" height="16" /></a><!-- AddThis Bookmark Button END --> <!-- AddThis Feed Button BEGIN --><a title="Subscribe using any feed reader!" href="http://www.addthis.com/feed.php?pub=warpedjavaguy&amp;h1=http%3A%2F%2Fwarpedjavaguy.wordpress.com%2Ffeed%2F&amp;t1="><img src="http://s9.addthis.com/button1-fd.gif" border="0" alt="AddThis Feed Button" width="125" height="16" /></a><!-- AddThis Feed Button END --></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/warpedjavaguy.wordpress.com/110/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/warpedjavaguy.wordpress.com/110/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/warpedjavaguy.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/warpedjavaguy.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/warpedjavaguy.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/warpedjavaguy.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/warpedjavaguy.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/warpedjavaguy.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/warpedjavaguy.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/warpedjavaguy.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/warpedjavaguy.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/warpedjavaguy.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/warpedjavaguy.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/warpedjavaguy.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/warpedjavaguy.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/warpedjavaguy.wordpress.com/110/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=warpedjavaguy.wordpress.com&amp;blog=809469&amp;post=110&amp;subd=warpedjavaguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://warpedjavaguy.wordpress.com/2008/09/16/implicitly-formatted-exceptions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b5c8e528c21ff5b742756afdef7a9219?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif" medium="image">
			<media:title type="html">WarpedJavaGuy</media:title>
		</media:content>

		<media:content url="http://s9.addthis.com/button1-bm.gif" medium="image">
			<media:title type="html">AddThis Social Bookmark Button</media:title>
		</media:content>

		<media:content url="http://s9.addthis.com/button1-fd.gif" medium="image">
			<media:title type="html">AddThis Feed Button</media:title>
		</media:content>
	</item>
		<item>
		<title>Polymorphism by Closure Injection?</title>
		<link>http://warpedjavaguy.wordpress.com/2008/09/04/polymorphism-by-closure-injection/</link>
		<comments>http://warpedjavaguy.wordpress.com/2008/09/04/polymorphism-by-closure-injection/#comments</comments>
		<pubDate>Thu, 04 Sep 2008 13:31:38 +0000</pubDate>
		<dc:creator>warpedjavaguy</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[closures]]></category>

		<guid isPermaLink="false">http://warpedjavaguy.wordpress.com/?p=33</guid>
		<description><![CDATA[Instead of defining many classes to do the same thing differently through polymorphism, you could define just one class and achieve the same through closure injection! &#160; I recently downloaded the feature complete BGGA closures prototype and had a bit of a play. My first experiment was to refactor an existing codebase and replace all [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=warpedjavaguy.wordpress.com&amp;blog=809469&amp;post=33&amp;subd=warpedjavaguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p><em><br />
Instead of defining many classes to do the same thing differently through polymorphism, you could define just one class and achieve the same through closure injection!<br />
&nbsp;<br />
</em></p></blockquote>
<p>I recently downloaded the <a href="http://gafter.blogspot.com/2008/08/java-closures-prototype-feature.html">feature complete BGGA closures prototype</a> and had a bit of a play.  My first experiment was to refactor an existing codebase and replace all anonymous inner classes with closures.  The ones that extended single abstract method (SAM) interfaces were easy to convert.  The ones that extended multiple method (non-SAM) types were a bit trickier.  In the end though, I managed to successfully convert all of them, and with very little effort.</p>
<p>In converting the non-SAM types, I discovered that the functional equivalent of polymorphism can be achieved by injecting closures into a single concrete implementation having no subclasses.</p>
<p>The codebase I refactored was a small (fictitious) railroad application that provided customers with information about routes.  In particular, it calculated things like the number of routes between two cities, the number of routes that do not exceed a given number of stops, the distances of individual routes, and the like.  It did this by deriving routes on the fly from a given set of legs and dynamically yielding only those that match a given predicate (or condition).</p>
<p>Here is the original predicate code using anonymous inner classes:</p>
<p><pre class="brush: java;">
public abstract class Predicate&lt;T&gt; {

  public boolean eligible(T item) {
    return yield(item);
  }

  public abstract boolean yield(T item);

  /* Pre-defined predicates follow */

  public static Predicate&lt;Route&gt; routesWithMaxStops(final int maxStops) {
    return new Predicate&lt;Route&gt;() {
      public boolean yield(Route route) {
        return route.getLegs().size() &lt;= maxStops;
      }
    };
  }

  public static Predicate&lt;Route&gt; routesWithStops(final int stops) {
    return new Predicate&lt;Route&gt;() {
      public boolean eligible(Route route) {
        return route.getLegs().size() &lt;= stops;
      }
      public boolean yield(Route route) {
        return route.getLegs().size() == stops;
      }
    };
  }

}
</pre></p>
<p>In the above code only two predefined predicates are shown for brevity (the actual code has got more).</p>
<p>Note that the predicate has two methods.  Only routes for which both methods return true are yielded.</p>
<ul>
<li><em>eligible</em> &#8211; determines if a route satisfies a boundary condition</li>
<li><em>yield</em> &#8211; determines if a route should be yielded</li>
</ul>
<p>Here is the converted closure equivalent:</p>
<p><pre class="brush: java;">
public class Predicate&lt;T&gt; {

  private {T =&gt; boolean} eligible;
  private {T =&gt; boolean} yield;

  public Predicate({T =&gt; boolean} yield) {
    this(yield, yield);
  }

  public Predicate({T =&gt; boolean} eligible, {T =&gt; boolean} yield) {
    this.eligible = eligible;
    this.yield = yield;
  }

  public boolean eligible(T item) {
    return eligible.invoke(item);
  }

  public boolean yield(T item) {
    return yield.invoke(item);
  }

  /* Pre-defined predicates follow */

  public static Predicate&lt;Route&gt; routesWithMaxStops(int maxStops) {
    return new Predicate&lt;Route&gt;(
      {Route route =&gt; route.getLegs().size() &lt;= maxStops});
  }

  public static Predicate&lt;Route&gt; routesWithStops(int stops) {
    return new Predicate&lt;Route&gt;(
      {Route route =&gt; route.getLegs().size() &lt;= stops},
      {Route route =&gt; route.getLegs().size() == stops});
  }

}
</pre></p>
<p>If you look carefully, you will notice that both the original and converted code produce a redundant invocation when the <em>eligible</em> and <em>yield</em> expressions are identical.  Fortunately, this is a flaw that can be very easily corrected in the closure version.</p>
<p>A possible correction is shown below (see lines 5, 17, 18, and 22):</p>
<p><pre class="brush: java;">
public class Predicate&lt;T&gt; {

  private {T =&gt; boolean} eligible;
  private {T =&gt; boolean} yield;
  private boolean isEligible;

  public Predicate({T =&gt; boolean} yield) {
    this(yield, yield);
  }

  public Predicate({T =&gt; boolean} eligible, {T =&gt; boolean} yield) {
    this.eligible = eligible;
    this.yield = yield;
  }

  public boolean eligible(T item) {
    isEligible = eligible.invoke(item);
    return isEligible;
  }

  public boolean yield(T item) {
    return (isEligible &amp;&amp; eligible == yield) ? true : yield.invoke(item);
  }

  /* Unchanged pre-defined predicates not shown here */

}
</pre></p>
<p>Applying the same correction to the original closureless version is not nearly as simple.  It would require a more complex solution and could even involve changing the interface.</p>
<p>It is very interesting that polymorphic functionality can be achieved by injecting closures into one concrete class instead of defining multiple subclasses of an abstract class.  Closures and anonymous inner classes, injection and inheritance, deferred execution and late binding.  So many great choices!</p>
<p><!-- AddThis Bookmark Button BEGIN --><a title="Bookmark using any bookmark manager!" href="http://www.addthis.com/bookmark.php?url=http://warpedjavaguy.wordpress.com/2008/09/04/polymorphism-by-closure-injection/" target="_blank"><img src="http://s9.addthis.com/button1-bm.gif" border="0" alt="AddThis Social Bookmark Button" width="125" height="16" /></a><!-- AddThis Bookmark Button END --> <!-- AddThis Feed Button BEGIN --><a title="Subscribe using any feed reader!" href="http://www.addthis.com/feed.php?pub=warpedjavaguy&amp;h1=http%3A%2F%2Fwarpedjavaguy.wordpress.com%2Ffeed%2F&amp;t1="><img src="http://s9.addthis.com/button1-fd.gif" border="0" alt="AddThis Feed Button" width="125" height="16" /></a><!-- AddThis Feed Button END --></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/warpedjavaguy.wordpress.com/33/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/warpedjavaguy.wordpress.com/33/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/warpedjavaguy.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/warpedjavaguy.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/warpedjavaguy.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/warpedjavaguy.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/warpedjavaguy.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/warpedjavaguy.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/warpedjavaguy.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/warpedjavaguy.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/warpedjavaguy.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/warpedjavaguy.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/warpedjavaguy.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/warpedjavaguy.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/warpedjavaguy.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/warpedjavaguy.wordpress.com/33/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=warpedjavaguy.wordpress.com&amp;blog=809469&amp;post=33&amp;subd=warpedjavaguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://warpedjavaguy.wordpress.com/2008/09/04/polymorphism-by-closure-injection/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b5c8e528c21ff5b742756afdef7a9219?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif" medium="image">
			<media:title type="html">WarpedJavaGuy</media:title>
		</media:content>

		<media:content url="http://s9.addthis.com/button1-bm.gif" medium="image">
			<media:title type="html">AddThis Social Bookmark Button</media:title>
		</media:content>

		<media:content url="http://s9.addthis.com/button1-fd.gif" medium="image">
			<media:title type="html">AddThis Feed Button</media:title>
		</media:content>
	</item>
		<item>
		<title>Java Closures &#8211; The Fundamental Benefit</title>
		<link>http://warpedjavaguy.wordpress.com/2008/06/25/java-closures-the-fundamental-benefit/</link>
		<comments>http://warpedjavaguy.wordpress.com/2008/06/25/java-closures-the-fundamental-benefit/#comments</comments>
		<pubDate>Wed, 25 Jun 2008 12:32:41 +0000</pubDate>
		<dc:creator>warpedjavaguy</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[closures]]></category>

		<guid isPermaLink="false">http://warpedjavaguy.wordpress.com/?p=32</guid>
		<description><![CDATA[Avoiding redundant code is a basic programming instinct. &#160; How many times have you written a piece of code and thought &#8220;I wish I could reuse this block of code&#8221;? How many times have you refactored existing code to remove redundancies? How many times have you written the same block of code more than once [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=warpedjavaguy.wordpress.com&amp;blog=809469&amp;post=32&amp;subd=warpedjavaguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p><em><br />
Avoiding redundant code is a basic programming instinct.<br />
&nbsp;<br />
</em></p></blockquote>
<p>How many times have you written a piece of code and thought &#8220;I wish I could reuse this block of code&#8221;?  How many times have you refactored existing code to remove redundancies?  How many times have you written the same block of code more than once before realising that an abstraction exists?  How many times have you extracted such abstractions successfully?   How difficult was it to do and how much effort was involved?  How constrained were you by the current Java language constructs?  These are all questions pertaining to the everyday challenges we face as Java programmers in our struggles to achieve zero code redundancy.</p>
<p>Closures are reusable blocks of code that capture the environment and can be passed around as method arguments for immediate or deferred execution.  Why do we need them in Java?  There are <a href="http://tech.puredanger.com/java7#closures">many reasons for and against</a>, but the fundamental benefit they provide is the facilitation of redundant code avoidance.  The <a href="http://www.javac.info/closures-v05.html">current Java closures specification</a> makes a strong point of this in the first paragraph where it states: &#8220;they allow one to more easily extract the common parts of two almost-identical pieces of code&#8221;.</p>
<p>Closures provide an elegant means of reusing blocks of code and avoiding code duplication without the boilerplate.  This is the fundamental benefit that closures bring to Java.  All other benefits are derived benefits inherited from this fundamental benefit.  In fact, all the needs addressed by the <a href="http://www.javac.info/consensus-closures-jsr.html">Java closures proposal</a> are all derived benefits.</p>
<p>I know I am just stating the obvious and reiterating my point here, but it is just too easy to overlook this one fundamental benefit and be overwhelmed by all others.  Java closures make it easier to eliminate redundant code and avoid it altogether!<br />
<!-- AddThis Bookmark Button BEGIN --><a title="Bookmark using any bookmark manager!" href="http://www.addthis.com/bookmark.php?url=http://warpedjavaguy.wordpress.com/2008/06/25/java-closures-the-fundamental-benefit" target="_blank"><img src="http://s9.addthis.com/button1-bm.gif" border="0" alt="AddThis Social Bookmark Button" width="125" height="16" /></a><!-- AddThis Bookmark Button END --> <!-- AddThis Feed Button BEGIN --><a title="Subscribe using any feed reader!" href="http://www.addthis.com/feed.php?pub=warpedjavaguy&amp;h1=http%3A%2F%2Fwarpedjavaguy.wordpress.com%2Ffeed%2F&amp;t1="><img src="http://s9.addthis.com/button1-fd.gif" border="0" alt="AddThis Feed Button" width="125" height="16" /></a><!-- AddThis Feed Button END --></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/warpedjavaguy.wordpress.com/32/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/warpedjavaguy.wordpress.com/32/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/warpedjavaguy.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/warpedjavaguy.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/warpedjavaguy.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/warpedjavaguy.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/warpedjavaguy.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/warpedjavaguy.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/warpedjavaguy.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/warpedjavaguy.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/warpedjavaguy.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/warpedjavaguy.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/warpedjavaguy.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/warpedjavaguy.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/warpedjavaguy.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/warpedjavaguy.wordpress.com/32/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=warpedjavaguy.wordpress.com&amp;blog=809469&amp;post=32&amp;subd=warpedjavaguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://warpedjavaguy.wordpress.com/2008/06/25/java-closures-the-fundamental-benefit/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b5c8e528c21ff5b742756afdef7a9219?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif" medium="image">
			<media:title type="html">WarpedJavaGuy</media:title>
		</media:content>

		<media:content url="http://s9.addthis.com/button1-bm.gif" medium="image">
			<media:title type="html">AddThis Social Bookmark Button</media:title>
		</media:content>

		<media:content url="http://s9.addthis.com/button1-fd.gif" medium="image">
			<media:title type="html">AddThis Feed Button</media:title>
		</media:content>
	</item>
		<item>
		<title>Closure Syntax Wars</title>
		<link>http://warpedjavaguy.wordpress.com/2008/02/28/closure-syntax-wars/</link>
		<comments>http://warpedjavaguy.wordpress.com/2008/02/28/closure-syntax-wars/#comments</comments>
		<pubDate>Thu, 28 Feb 2008 01:14:47 +0000</pubDate>
		<dc:creator>warpedjavaguy</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[closures]]></category>

		<guid isPermaLink="false">http://warpedjavaguy.wordpress.com/?p=31</guid>
		<description><![CDATA[Closures look weird and complicated but so does all other code in general. &#160; There seems to be some disagreement amongst the Java community about what the exact syntax for Java closures should be. The two currently most popular closure proposals are BGGA and FCM and they each use a different syntax. Neither syntax is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=warpedjavaguy.wordpress.com&amp;blog=809469&amp;post=31&amp;subd=warpedjavaguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p><em><br />
Closures look weird and complicated but so does all other code in general.<br />
&nbsp;<br />
</em></p></blockquote>
<p>There seems to be some disagreement amongst the Java community about what the exact syntax for Java closures should be.  The two currently most popular closure proposals are <a href="http://www.javac.info/">BGGA</a> and <a href="http://docs.google.com/Doc?id=ddhp95vd_0f7mcns">FCM</a> and they each use a different syntax.  Neither syntax is final and looking at the discussions and comments in recent <a href="http://java.net/pub/pq/196">polls</a> and <a href="http://weblogs.java.net/blog/alexwinston/archive/2008/02/closure_syntax_1.html">many</a> <a href="http://viewfromthefringe.blogspot.com/2008/02/alternate-syntax-for-java-closures.html">various</a> <a href="http://www.jroller.com/scolebourne/entry/fcm_prototype_available">blogs</a> it is evident that we all have our own opinions, preferences, and personal favourites (<a href="http://warpedjavaguy.wordpress.com/2008/02/21/pointer-syntax-for-java-closures/">myself included</a>).  And as developers why shouldn&#8217;t we?  We are the ones that will potentially have to write and maintain code that uses closures.  That&#8217;s why we care about the syntax.</p>
<p>The current BGGA proposal uses the &#8216;=&gt;&#8217; syntax.  Although this looks like an arrow that points to a block of code, it can sometimes trick the eye and easily be mistaken for the &#8216;&gt;=&#8217; and &#8216;&lt;=&#8217; conditional operators.  Consider the example below which defines a function that returns a boolean and accepts a parameter of type int and compares it against two variables.</p>
<p><pre class="brush: java;">
{int =&gt; boolean} f = { int x =&gt; y &lt;= x &amp;&amp; x &lt;= z };</pre></p>
<p>Now consider the same example using the current FCM &#8216;#&#8217; syntax.  This style is designed to look and feel like Java method signatures.  It is less confusing and easier to grasp though.</p>
<p><pre class="brush: java;">
&lt;ol&gt;
  &lt;li&gt;(boolean(int)) f =  #(int x) { y &lt;= x &amp;&amp; x &lt;= z };</pre></li>
</ol>
<p>In my previous post I questioned why we shouldn&#8217;t consider <a href="http://warpedjavaguy.wordpress.com/2008/02/21/pointer-syntax-for-java-closures/">Java Method Pointers</a> (JMP).  The inspiration for this was a familiar but variant form of the C/C++ function pointer syntax.  The same example would look something like this:</p>
<p><pre class="brush: java;">
boolean* (int) f = (int x) { y &lt;= x &amp;&amp; x &lt;= z };</pre></p>
<p>Closures are indeed an alien concept to Java and they sure look alien too.  Throw generics into the mix and they can look even more weird and complicated.Take a look at the following two examples:</p>
<p>Neal Gafter&#8217;s <a href="http://gafter.blogspot.com/2008/02/closures-puzzler-neapolitan-ice-cream.html">closures puzzler</a> which transforms a list of objects of type T to a list of objects of type U.</p>
<p><pre class="brush: java;">
static  List&lt;U&gt; map(List list, {T=&gt;U} transform) {
  List&lt;U&gt; result = new ArrayList&lt;U&gt;(list.size());
  for (T t : list) {
    result.add(transform.invoke(t));
  }
  return result;
}</pre></p>
<p>Stephen Colebourne&#8217;s <a href="http://www.jroller.com/scolebourne/entry/evaluating_bgga_closures">evaluating BGGA example</a> which converts an object of type T to an object of type U.</p>
<p><pre class="brush: java;">
public  {T =&gt; U} converter({=&gt; T} a, {=&gt; U} b, {T =&gt; U} c) {
  return {T t =&gt; a.invoke().equals(t) ? b.invoke() : c.invoke(t)};
}</pre></p>
<p>At the end of the day, we really want closures in Java for doing <a href="http://www.javac.info/consensus-closures-jsr.html">these nice things</a>:</p>
<ul>
<li>Simplifying anonymous class instance creation</li>
<li>Automating resource management/termination (<a href="http://docs.google.com/View?docid=dffxznxr_1nmsqkz">ARM blocks</a>)</li>
<li>Using for-each style loop constructs</li>
<li>Writing less boilerplate code</li>
</ul>
<p>Closures would make it all possible.  A lot of the complicated closure constructs involving generics would be integrated into the API.  Developers would not have to write those.  Java would provide them out of the box.</p>
<p>The more you look at closures and read about them the more familiar and less alien they become.  Just like everything else, they do take a little getting used to.  The question is what closure syntax do we want to get used to?   Will it be good for Java?  One day we may have to decide.  Until then, the syntax war will continue.</p>
<p><!-- AddThis Bookmark Button BEGIN --><a title="Bookmark using any bookmark manager!" href="http://www.addthis.com/bookmark.php?url=http://warpedjavaguy.wordpress.com/2008/02/28/closure-syntax-wars/" target="_blank"><img src="http://s9.addthis.com/button1-bm.gif" border="0" alt="AddThis Social Bookmark Button" width="125" height="16" /></a><!-- AddThis Bookmark Button END --> <!-- AddThis Feed Button BEGIN --><a title="Subscribe using any feed reader!" href="http://www.addthis.com/feed.php?pub=warpedjavaguy&amp;h1=http%3A%2F%2Fwarpedjavaguy.wordpress.com%2Ffeed%2F&amp;t1="><img src="http://s9.addthis.com/button1-fd.gif" border="0" alt="AddThis Feed Button" width="125" height="16" /></a><!-- AddThis Feed Button END --></p>
<p><a class="tr-linkcount" href="http://technorati.com/search/http://warpedjavaguy.wordpress.com/2008/02/28/closure-syntax-wars/"><img style="border:0 none;vertical-align:middle;margin-left:.4em;" src="http://static.technorati.com/static/img/pub/icon-utag-16x13.png?tag=warpedjavaguy" alt=" " />View Reactions</a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/warpedjavaguy.wordpress.com/31/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/warpedjavaguy.wordpress.com/31/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/warpedjavaguy.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/warpedjavaguy.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/warpedjavaguy.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/warpedjavaguy.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/warpedjavaguy.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/warpedjavaguy.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/warpedjavaguy.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/warpedjavaguy.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/warpedjavaguy.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/warpedjavaguy.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/warpedjavaguy.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/warpedjavaguy.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/warpedjavaguy.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/warpedjavaguy.wordpress.com/31/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=warpedjavaguy.wordpress.com&amp;blog=809469&amp;post=31&amp;subd=warpedjavaguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://warpedjavaguy.wordpress.com/2008/02/28/closure-syntax-wars/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b5c8e528c21ff5b742756afdef7a9219?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif" medium="image">
			<media:title type="html">WarpedJavaGuy</media:title>
		</media:content>

		<media:content url="http://s9.addthis.com/button1-bm.gif" medium="image">
			<media:title type="html">AddThis Social Bookmark Button</media:title>
		</media:content>

		<media:content url="http://s9.addthis.com/button1-fd.gif" medium="image">
			<media:title type="html">AddThis Feed Button</media:title>
		</media:content>

		<media:content url="http://static.technorati.com/static/img/pub/icon-utag-16x13.png?tag=warpedjavaguy" medium="image">
			<media:title type="html"> </media:title>
		</media:content>
	</item>
		<item>
		<title>Pointer Syntax for Java Closures</title>
		<link>http://warpedjavaguy.wordpress.com/2008/02/21/pointer-syntax-for-java-closures/</link>
		<comments>http://warpedjavaguy.wordpress.com/2008/02/21/pointer-syntax-for-java-closures/#comments</comments>
		<pubDate>Thu, 21 Feb 2008 10:51:30 +0000</pubDate>
		<dc:creator>warpedjavaguy</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[closures]]></category>

		<guid isPermaLink="false">http://warpedjavaguy.wordpress.com/?p=30</guid>
		<description><![CDATA[If Java closures are pointers to methods then we should make them look like pointers to methods. &#160; Closures for Java are a hot topic yet again. The BGGA proposal is currently leading in the polls. It seems that most people who want closures want full closure support. I like the BGGA proposal, but I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=warpedjavaguy.wordpress.com&amp;blog=809469&amp;post=30&amp;subd=warpedjavaguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p><em><br />
If Java closures are pointers to methods then we should make them look like pointers to methods.<br />
&nbsp;<br />
</em></p></blockquote>
<p>Closures for Java are a hot topic yet again.  The BGGA proposal is currently leading in the <a href="http://java.net/pub/pq/196">polls</a>.  It seems that most people who want closures want full closure support.  I like the BGGA proposal, but I think the syntax can be improved to look more familiar and less verbose.</p>
<p>I generally tend to think of Java closures in the same way that I think of C/C++ function pointers (or member function pointers).  A lot of programmers like myself transitioned from C++ to Java back in 1999.  Java borrows a lot of the syntax from C++ and it was a natural transition for C++ programmers to move to Java.  Given this, I cant help but question whether or not we should adopt the familiar C++ function pointer syntax for Java closures.  That way the syntax (at least) would not be too alien to us.</p>
<p>Borrowing the examples from Stephen Colebourne&#8217;s weblog entry on <a href="http://www.jroller.com/scolebourne/entry/evaluating_bgga_closures">evaluating BGGA</a>, we have the following syntax comparisons:</p>
<p><a href="http://www.javac.info/">BGGA syntax</a>:</p>
<p><pre class="brush: java;">
int y = 6;
{int =&gt; boolean} a = {int x =&gt; x &lt;= y};
{int =&gt; boolean} b = {int x =&gt; x &gt;= y};
boolean c = a.invoke(3) &amp;&amp; b.invoke(7);</pre></p>
<p><pre class="brush: java;">
public {T =&gt; U} converter({=&gt; T} a, {=&gt; U} b, {T =&gt; U} c) {
  return {T t =&gt; a.invoke().equals(t) ? b.invoke() : c.invoke(t)};
}</pre></p>
<p>Java Method Pointer syntax (simplified C/C++ pointer syntax for Java):</p>
<p><pre class="brush: java;">
int y = 6;
boolean* (int) a = (int x) {x &lt;= y};
boolean* (int) b = (int x) {x &gt;= y};
boolean c = a.invoke(3) &amp;&amp; b.invoke(7);</pre></p>
<p><pre class="brush: java;">
public  U* (T) converter(T* a, U* b, U* (T) c) {
  return (T t) {a.invoke().equals(t) ? b.invoke() : c.invoke(t)};
}</pre></p>
<p>In addition to this, we could also borrow the &amp; syntax and reference existing static and instance methods like this:</p>
<p><pre class="brush: java;">
boolean* (int) a = class&amp;method(int);
boolean* (int) b = instance&amp;method(int);
boolean* (int) c = this&amp;method(int);</pre></p>
<p>If we want closures in Java, why not borrow the C/C++ pointer syntax and think of them as pointers to methods if that&#8217;s what they are?  Most of the Java syntax is borrowed from C++ after all.  I understand that function pointers do not fit well in the OO paradigm but I&#8217;m not talking about pointers to functions here.  I&#8217;m instead talking about pointers to methods in the OO world of Java.</p>
<p><!-- AddThis Bookmark Button BEGIN --><a title="Bookmark using any bookmark manager!" href="http://www.addthis.com/bookmark.php?url=http://warpedjavaguy.wordpress.com/2008/02/21/pointer-syntax-for-java-closures/" target="_blank"><img src="http://s9.addthis.com/button1-bm.gif" border="0" alt="AddThis Social Bookmark Button" width="125" height="16" /></a><!-- AddThis Bookmark Button END --> <!-- AddThis Feed Button BEGIN --><a title="Subscribe using any feed reader!" href="http://www.addthis.com/feed.php?pub=warpedjavaguy&amp;h1=http%3A%2F%2Fwarpedjavaguy.wordpress.com%2Ffeed%2F&amp;t1="><img src="http://s9.addthis.com/button1-fd.gif" border="0" alt="AddThis Feed Button" width="125" height="16" /></a><br />
<!-- AddThis Feed Button END --><br />
<a class="tr-linkcount" href="http://technorati.com/search/http://warpedjavaguy.wordpress.com/2008/02/21/pointer-syntax-for-java-closures/"><img style="border:0 none;vertical-align:middle;margin-left:.4em;" src="http://static.technorati.com/static/img/pub/icon-utag-16x13.png?tag=warpedjavaguy" alt=" " />View Reactions</a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/warpedjavaguy.wordpress.com/30/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/warpedjavaguy.wordpress.com/30/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/warpedjavaguy.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/warpedjavaguy.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/warpedjavaguy.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/warpedjavaguy.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/warpedjavaguy.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/warpedjavaguy.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/warpedjavaguy.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/warpedjavaguy.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/warpedjavaguy.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/warpedjavaguy.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/warpedjavaguy.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/warpedjavaguy.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/warpedjavaguy.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/warpedjavaguy.wordpress.com/30/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=warpedjavaguy.wordpress.com&amp;blog=809469&amp;post=30&amp;subd=warpedjavaguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://warpedjavaguy.wordpress.com/2008/02/21/pointer-syntax-for-java-closures/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b5c8e528c21ff5b742756afdef7a9219?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif" medium="image">
			<media:title type="html">WarpedJavaGuy</media:title>
		</media:content>

		<media:content url="http://s9.addthis.com/button1-bm.gif" medium="image">
			<media:title type="html">AddThis Social Bookmark Button</media:title>
		</media:content>

		<media:content url="http://s9.addthis.com/button1-fd.gif" medium="image">
			<media:title type="html">AddThis Feed Button</media:title>
		</media:content>

		<media:content url="http://static.technorati.com/static/img/pub/icon-utag-16x13.png?tag=warpedjavaguy" medium="image">
			<media:title type="html"> </media:title>
		</media:content>
	</item>
		<item>
		<title>The Mind of a Programmer</title>
		<link>http://warpedjavaguy.wordpress.com/2008/01/18/the-mind-of-a-programmer/</link>
		<comments>http://warpedjavaguy.wordpress.com/2008/01/18/the-mind-of-a-programmer/#comments</comments>
		<pubDate>Fri, 18 Jan 2008 00:41:59 +0000</pubDate>
		<dc:creator>warpedjavaguy</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[learning]]></category>

		<guid isPermaLink="false">http://warpedjavaguy.wordpress.com/2008/01/18/the-mind-of-a-programmer/</guid>
		<description><![CDATA[In my follow up post I delve even deeper into the odd and even number problem and discover a pattern that is common to both humans and machines.  A natural born programmer already knows that.  I am not one of them.  But I am pleased and grateful to have learned about them here :)  <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=warpedjavaguy.wordpress.com&amp;blog=809469&amp;post=29&amp;subd=warpedjavaguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p><em><br />
Good programmers are good at solving problems because they consider all the dimensions.<br />
&nbsp;<br />
</em></p></blockquote>
<p>A short while ago I published a post about <a href="http://warpedjavaguy.wordpress.com/2007/06/20/natural-born-programmers/">natural born programmers</a> and questioned whether or not they exist.  When I was writing it I was thinking about how programmers go about coding solutions to problems that they already know how to solve. I was trying to tap into the mind of a programmer and discover how it thinks.  I demonstrated two approaches to solving the simple problem of determining whether a number is odd or even.  One solution used a &#8216;smart&#8217; human approach and the other a &#8216;simple&#8217; math approach.  It generated some good discussions and triggered <a href="http://www.atomicmpc.com.au/forums.asp?s=2&amp;c=10&amp;t=4311">various</a> <a href="http://technorati.com/search/http://warpedjavaguy.wordpress.com/2007/06/20/natural-born-programmers/">reactions</a>.  The most interesting one was <a href="http://programming.reddit.com/info/203sv/comments/">this one</a>.  It discusses <a href="http://warpedjavaguy.wordpress.com/2007/06/20/natural-born-programmers/#comment-3">my first response</a> to the <a href="http://warpedjavaguy.wordpress.com/2007/06/20/natural-born-programmers/#comment-2">first comment</a> posted by Matt Turner.</p>
<p>The simple math solution that I suggested was this:<br />
<pre class="brush: java;">
// if divisible by 2 then is even else is odd
boolean isEven = number % 2 == 0;
</pre></p>
<p>The alternative and bitwise solution that Matt suggested was this:<br />
<pre class="brush: java;">
// if last bit is 0 then is even else is odd
boolean isEven = (number &amp; 1) == 0;
</pre></p>
<p>I knew that the &amp;1 solution was functionally equivalent to the %2 solution but I wasn&#8217;t exactly sure if it was also equally as efficient (or even better).  I had to prove it.  So I knocked up a quick test program to compare the execution times.  When I ran the program I observed that both of them did take the same time to execute.  I also analysed the generated bytecode and found that the %2 solution used the IREM bytecode instruction and that the &amp;1 operation used the IAND instruction.  My bytecode findings attracted <a href="http://warpedjavaguy.wordpress.com/2007/06/20/natural-born-programmers/#comment-9">these</a> <a href="http://warpedjavaguy.wordpress.com/2007/06/20/natural-born-programmers/#comment-127">comments</a> by Michael Speer and Charlie Chan respectively (and <a href="http://warpedjavaguy.wordpress.com/2007/06/20/natural-born-programmers/#comment-21">other anonymous comments</a> too).  Having done a bit of assembler, C, and C++ in my not too old school days, I do have some experience in binary arithmetic and native code optimisation.  So I can appreciate the &amp;1 solution.  But I never expect to have to apply this knowledge directly to Java programming.  I always expect Java to perform all trivial optimisations on my behalf.  I should not have to optimise my Java code at this level.  I should just write code that expresses what I want in the simplest and clearest way possible.</p>
<p>It has often been said by many programmers that there is no one right solution to a problem.  That is definitely the case here.  But there is something more interesting here though.  If you study the &amp;1 solution you will find that it very closely resembles the &#8216;smart&#8217; human optimised approach to solving the problem.  How?  Remember that smart humans can tell whether a number is even or odd just by looking at the last digit.  The &amp;1 solution emulates exactly that, yes indeed!  The difference is that humans look at the right-most digit whereas machines look at the right-most bit.  We have identified a pattern here that is common to both humans and machines.  Interesting!</p>
<p>But wait!  The %2 approach is a more natural and readable expression of the mathematical definition and is also more easily understood by us humans as adopters of the base 10 decimal number system.  It directly expresses at a high level the definition that all even numbers are divisible by two and that all odd numbers are not.  At the lower level it expresses it as an IREM bytecode instruction. At the even lower machine code level it expresses it as native assembly instructions.  We are now in the world of base 2 binary numbers where operations like &#8216;divide by two&#8217; involve shifting all bits one place to the right and carrying the right most bit (the remainder).  Bits can be checked, set, and toggled with bitwise AND, OR, and XOR operations.  At this stage, the %2 instruction is optimised for the machine and more closely resembles the &amp;1 operation.  So at the binary level, one can deduce that the %2 operation is essentially equivalent to &amp;1.</p>
<p>By solving problems and comparing solutions we are able to identify common patterns.  Gifted programmers are naturally good at it!  These are the things we learn and the things that go on in our minds as programmers.</p>
<p><!-- AddThis Bookmark Button BEGIN --><a href="http://www.addthis.com/bookmark.php?url=http://warpedjavaguy.wordpress.com/2008/01/18/the-mind-of-a-programmer/" title="Bookmark using any bookmark manager!" target="_blank"><img src="http://s9.addthis.com/button1-bm.gif" alt="AddThis Social Bookmark Button" border="0" height="16" width="125" /></a><!-- AddThis Bookmark Button END --> <!-- AddThis Feed Button BEGIN --><a href="http://www.addthis.com/feed.php?pub=warpedjavaguy&amp;h1=http%3A%2F%2Fwarpedjavaguy.wordpress.com%2Ffeed%2F&amp;t1=" title="Subscribe using any feed reader!"><img src="http://s9.addthis.com/button1-fd.gif" alt="AddThis Feed Button" border="0" height="16" width="125" /></a><!-- AddThis Feed Button END --></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/warpedjavaguy.wordpress.com/29/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/warpedjavaguy.wordpress.com/29/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/warpedjavaguy.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/warpedjavaguy.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/warpedjavaguy.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/warpedjavaguy.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/warpedjavaguy.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/warpedjavaguy.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/warpedjavaguy.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/warpedjavaguy.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/warpedjavaguy.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/warpedjavaguy.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/warpedjavaguy.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/warpedjavaguy.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/warpedjavaguy.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/warpedjavaguy.wordpress.com/29/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=warpedjavaguy.wordpress.com&amp;blog=809469&amp;post=29&amp;subd=warpedjavaguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://warpedjavaguy.wordpress.com/2008/01/18/the-mind-of-a-programmer/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b5c8e528c21ff5b742756afdef7a9219?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif" medium="image">
			<media:title type="html">WarpedJavaGuy</media:title>
		</media:content>

		<media:content url="http://s9.addthis.com/button1-bm.gif" medium="image">
			<media:title type="html">AddThis Social Bookmark Button</media:title>
		</media:content>

		<media:content url="http://s9.addthis.com/button1-fd.gif" medium="image">
			<media:title type="html">AddThis Feed Button</media:title>
		</media:content>
	</item>
		<item>
		<title>Test Driven Rewrites (for Programmers)</title>
		<link>http://warpedjavaguy.wordpress.com/2007/12/20/test-driven-rewrites-for-programmers/</link>
		<comments>http://warpedjavaguy.wordpress.com/2007/12/20/test-driven-rewrites-for-programmers/#comments</comments>
		<pubDate>Thu, 20 Dec 2007 10:54:41 +0000</pubDate>
		<dc:creator>warpedjavaguy</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[aop mocks testing]]></category>

		<guid isPermaLink="false">http://warpedjavaguy.wordpress.com/2007/12/20/test-driven-rewrites-for-programmers/</guid>
		<description><![CDATA[Why write mock objects manually when you can emulate them virtually? &#160; In my previous post on Test Driven Rewrites I described at a high level how I used virtual mock objects to deliver a regression test suite for an existing component and how I used that suite to test and develop a rewrite of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=warpedjavaguy.wordpress.com&amp;blog=809469&amp;post=28&amp;subd=warpedjavaguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p><i><br />
Why write mock objects manually when you can emulate them virtually?<br />
&nbsp;<br />
</i></p></blockquote>
<p>In my previous post on <a href="http://warpedjavaguy.wordpress.com/2007/12/11/test-driven-rewrites/">Test Driven Rewrites</a> I described at a high level how I used <a href="http://www.xprogramming.com/xpmag/virtualMockObjects.htm">virtual mock objects</a> to deliver a regression test suite for an existing component and how I used that suite to test and develop a rewrite of that component.  In it you&#8217;ll recall that the existing codebase had no test suite at all and that I had very little knowledge of the business domain.  I had to come up with a quick and easy way to create a test suite from scratch.  Here I present some code that shows how I did it using <a href="http://www.eclipse.org/aspectj/">AspectJ</a>, XML, and <a href="http://www.junit.org/">JUnit</a>.</p>
<p>The first thing I had to do was identify the following points in the codebase:</p>
<ol>
<li>The test point
<ul>
<li>This is the point in the application where the call to the component is made.  It is the call to the component method that will be put under test.</li>
</ul>
</li>
<li>All the mock points
<ul>
<li>These are all the points in the component where calls are made to other components and/or services.  They are the calls to the methods that need to be mocked.</li>
</ul>
</li>
</ol>
<p>Next, a TestCaseGenerator aspect was written to capture the arguments and return values of the test and mock points identified above.  This aspect defined two <a href="http://www.eclipse.org/aspectj/doc/released/progguide/semantics-pointcuts.html">point cuts</a> for matching the test and mock points respectively. &#8220;Around&#8221; <a href="http://www.eclipse.org/aspectj/doc/released/progguide/semantics-advice.html">advice</a> was used on each to capture and persist the arguments and return values of each call to an XML file.  A MethodCall POJO was created to encapsulate the name, arguments, and return values of individual method calls and <a href="http://castor.codehaus.org/xml-framework.html">Castor XML</a> was used to marshal it to XML.  The aspect code is shown below:<br />
<pre class="brush: java;">
public aspect TestCaseGenerator {

    pointcut testPoint() :
        execution (/* test-point method pattern */);

    pointcut mockPoints() :
        call (/* mock-points method pattern */)
        &amp;&amp; withincode(/* test-point method pattern*/);

    // output XML document
    private Document xmldoc;

    Object around() : testPoint() {

        /* instantiate new XML document here */

        // encapsulate invoked method data into POJO
        MethodCall methodCall = new MethodCall();
        methodCall.setMethod(
            thisJoinPoint.getSignature().toString());
        methodCall.setArgs(thisJoinPoint.getArgs());
        Object retValue = proceed();
        methodCall.setRetValue(retValue);

        /* marshal POJO into test-point XML element here */

        /* persist XML to file here */

        // pass back return value
        return retValue;
    }

    Object around() : mockPoints() {

        // encapsulate invoked method data into POJO
        MethodCall methodCall = new MethodCall();
        methodCall.setMethod(
            thisJoinPoint.getSignature().toString());
        methodCall.setArgs(thisJoinPoint.getArgs());
        Object retValue = proceed();
        methodCall.setRetValue(retValue);

        /* marshal POJO into mock-point XML element here */

        // pass back return value
        return retValue;
    }
}</pre><br />
This aspect was woven into the existing codebase which was then deployed locally.  So now an XML test case file was automatically generated by the aspect on the file system for every scenario that was executed on the deployed application.  The business identified all the scenarios that needed to be tested and a test case XML file was generated for each one in real time as it was executed on the system by a user.  The basic structure of the XML that was generated is shown below:<br />
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;&gt;
&lt;test-case&gt;
    &lt;test-point method=&quot;method pattern&quot;&gt;
        &lt;arguments&gt;
            ...
        &lt;/arguments&gt;
        &lt;return-value&gt;
            ...
        &lt;/return-value&gt;
    &lt;/test-point&gt;
    &lt;mock-point method=&quot;method pattern&quot;&gt;
        &lt;arguments&gt;
            ...
        &lt;/arguments&gt;
    &lt;/mock-point&gt;
    &lt;mock-point method=&quot;method pattern&quot;&gt;
        &lt;arguments&gt;
            ...
        &lt;/arguments&gt;
        &lt;return-value&gt;
            ...
        &lt;/return-value&gt;
    &lt;/mock-point&gt;
    ...
&lt;/test-case&gt;</pre><br />
Once the data for all the known use case scenarios had been captured in XML files, it was then time to start writing the JUnit test suite that would execute the tests.  This involved creating the following:</p>
<ol>
<li>A MockedTestCase class (extends JUnit TestCase)</li>
<li>A MockedTestSuite class (extends JUnit TestCase)</li>
<li>A VirtualMocker aspect</li>
</ol>
<p>The MockedTestCase class was implemented with a constructor that accepted a given test case XML file.  All the mock point data in the file was loaded into individual MethodCall POJO instances and stored in a Map keyed by the method signature pattern.  The map was bound to a thread local variable to make it thread safe and accessible to the virtual mocker aspect for mocking purposes.  The test point data was used to invoke the component in the test and to assert the returned result.  The Java code is shown below:<br />
<pre class="brush: java;">
public class MockedTestCase extends TestCase {

    public static final
        ThreadLocal&lt;Map&lt;String,MethodCall&gt;&gt; MOCKS =
           new ThreadLocal&lt;Map&lt;String,MethodCall&gt;&gt;();

    private File xmlFile;
    private MethodCall testPoint;

    public MockedTestCase(File xmlFile) {
        super(&quot;testIt&quot;);
        this.xmlFile = xmlFile;
    }

    // overrides super to return test case XML file name
    public String getName() {
        return xmlFile.getName();
    }

    protected void setUp() throws Exception {

        testPoint = new MethodCall();
        /* Unmarshal XML test-point into POJO */

        Map&lt;String,MethodCall&gt; mocks =
            new HashMap&lt;String,MethodCall&gt;();
        /* Unmarshal XML mock-points and load into Map */

        // store loaded mocks in thread local var
        MOCKS.set(mocks);
    }

    public void testIt() throws Exception {

        // invoke the test
        // - pass in test-point args and capture the result
        Object args = testPoint.getArgs();
        Object result = /* invocation goes here */;

        // assert the result
        assertValues(
            &quot;Unexpected result returned by &quot;
                + testPoint.getMethod(),
            testPoint.getRetValue(),
            result);
    }

    public static void assertValues(
        String msg, Object expected, Object actual) {
        /* Compare the two values here and throw assertion
            error if not the same. One generic way of doing
            this might involve marshaling both objects to XML
            and then comparing the two with an XML diff utility. */
    }
}</pre><br />
The MockedTestSuite class was implemented to load and run every test case.  This was done by loading all the XML test case files from the file system, instantiating individual MockedTestCase instances for each one, and adding them all to the suite of tests to be executed.</p>
<p>The VirtualMocker aspect was defined to intercept all the mock-points using an &#8220;around&#8221; <a href="http://www.eclipse.org/aspectj/doc/released/progguide/semantics-advice.html">advice</a> which asserted the incoming arguments against the mocked arguments for the call before returning the mocked return value.  Access to all mock point data was provided in a Map contained in the thread local variable as loaded by the currently executing MockedTestCase.  The aspect code is shown below:<br />
<pre class="brush: java;">
public aspect VirtualMocker {

    pointcut mockPoints() :
        call (/* mock-points method pattern */)
        &amp;&amp; withincode(/*test-point method pattern*/);

    Object around() : mockPoints() {

        // retrieve mock data
        Map&lt;String,MethodCall&gt; mocks =
            MockedTestCase.MOCKS.get();
        MethodCall mock = mocks.get(
            thisJoinPoint.getSignature().toString());

        // assert input and return output
        MockedTestCase.assertValues(
            &quot;Unexpected input arguments passed to &quot;
                + mock.getMethod(),
            mock.getArgs(),
            thisJoinPoint.getArgs());
        return mock.getRetValue();
    }
}</pre><br />
The VirtualMocker aspect was woven into the existing codebase and the MockedTestSuite was executed over it to perform all the tests.  The same aspect was then woven into the new codebase and used to facilitate the test driven development of the rewrite.</p>
<p>Each XML test case file contained all the mock data that was required to test the same scenario that generated it.  The VirtualMocker aspect used the data to do all the mocking in all the tests.  No mock objects or test data fixtures were manually coded <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
&nbsp;<br />
<!-- AddThis Bookmark Button BEGIN --><a href="http://www.addthis.com/bookmark.php?url=http://warpedjavaguy.wordpress.com/2007/12/20/test-driven-rewrites-for-programmers/" title="Bookmark using any bookmark manager!" target="_blank"><img src="http://s9.addthis.com/button1-bm.gif" alt="AddThis Social Bookmark Button" border="0" height="16" width="125" /></a> <!-- AddThis Feed Button BEGIN --><a href="http://www.addthis.com/feed.php?pub=warpedjavaguy&amp;h1=http%3A%2F%2Fwarpedjavaguy.wordpress.com%2Ffeed%2F&amp;t1=" title="Subscribe using any feed reader!"><img src="http://s9.addthis.com/button1-fd.gif" alt="AddThis Feed Button" border="0" height="16" width="125" /></a><!-- AddThis Feed Button END --></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/warpedjavaguy.wordpress.com/28/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/warpedjavaguy.wordpress.com/28/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/warpedjavaguy.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/warpedjavaguy.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/warpedjavaguy.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/warpedjavaguy.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/warpedjavaguy.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/warpedjavaguy.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/warpedjavaguy.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/warpedjavaguy.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/warpedjavaguy.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/warpedjavaguy.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/warpedjavaguy.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/warpedjavaguy.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/warpedjavaguy.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/warpedjavaguy.wordpress.com/28/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=warpedjavaguy.wordpress.com&amp;blog=809469&amp;post=28&amp;subd=warpedjavaguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://warpedjavaguy.wordpress.com/2007/12/20/test-driven-rewrites-for-programmers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b5c8e528c21ff5b742756afdef7a9219?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif" medium="image">
			<media:title type="html">WarpedJavaGuy</media:title>
		</media:content>

		<media:content url="http://s9.addthis.com/button1-bm.gif" medium="image">
			<media:title type="html">AddThis Social Bookmark Button</media:title>
		</media:content>

		<media:content url="http://s9.addthis.com/button1-fd.gif" medium="image">
			<media:title type="html">AddThis Feed Button</media:title>
		</media:content>
	</item>
	</channel>
</rss>
