<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>codeflo.ws</title>
	
	<link>http://codeflows.wordpress.com</link>
	<description>gently down the stream</description>
	<lastBuildDate>Wed, 03 Jun 2009 15:02:24 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<image>
		<url>http://www.gravatar.com/blavatar/7def9150bb32f3439a87f29d9804119f?s=96&amp;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>codeflo.ws</title>
		<link>http://codeflows.wordpress.com</link>
	</image>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/codeflows" type="application/rss+xml" /><item>
		<title>1000 * 60 * 60 * 24</title>
		<link>http://feedproxy.google.com/~r/codeflows/~3/Euoh-m0F6YY/</link>
		<comments>http://codeflows.wordpress.com/2009/06/03/1000-60-60-24/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 15:02:24 +0000</pubDate>
		<dc:creator>Jari</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://codeflows.wordpress.com/?p=78</guid>
		<description><![CDATA[There was a time when dealing with dates and times in Java was god-awful. With Joda Time, everything&#8217;s a breeze. Not only are date-based calculations easy, but you can also make your domain code less anemic by utilizing the library to its full extent.
Case in point: I had a method that returned objects due for [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflows.wordpress.com&blog=1742247&post=78&subd=codeflows&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>There was a time when dealing with dates and times in Java was god-awful. With <a href="http://joda-time.sourceforge.net/">Joda Time</a>, everything&#8217;s a breeze. Not only are date-based calculations easy, but you can also make your domain code less anemic by utilizing the library to its full extent.</p>
<p>Case in point: I had a method that returned objects due for removal in the next <em>n</em> months. Its signature first looked like this:</p>
<pre name="code" class="java">

List&lt;Thing&gt; findThingsDueForRemovalIn(int months);
</pre>
<p>Using Joda, I first found a way to make the parameter type communicate the intent better. Enter <a href="http://joda-time.sourceforge.net/apidocs/org/joda/time/Months.html">Months</a>:</p>
<pre name="code" class="java">

List&lt;Thing&gt; findThingsDueForRemovalIn(Months months);
</pre>
<p>Now you can&#8217;t just call the method without thinking first; we actually had a bug in production recently due to one <code>setXXXTimeout(...)</code> method accepting seconds and the other milliseconds, both as primitive numbers. In the same class. Oh, the confusion.</p>
<p>The implementation is clean as well, something along the lines of</p>
<pre name="code" class="java">

public List&lt;Thing&gt; findThingsDueForRemovalIn(Months months) {
  ...
  final LocalDate today = new LocalDate();
  someQuery.setInclusiveDateRange(today, today.plus(months));
  return someQuery.execute();
}
</pre>
<p>Small victories.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeflows.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeflows.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeflows.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeflows.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeflows.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeflows.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeflows.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeflows.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeflows.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeflows.wordpress.com/78/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflows.wordpress.com&blog=1742247&post=78&subd=codeflows&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://codeflows.wordpress.com/2009/06/03/1000-60-60-24/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">jari</media:title>
		</media:content>
	<feedburner:origLink>http://codeflows.wordpress.com/2009/06/03/1000-60-60-24/</feedburner:origLink></item>
		<item>
		<title>Today’s the day.</title>
		<link>http://feedproxy.google.com/~r/codeflows/~3/zdB0bA0nTe8/</link>
		<comments>http://codeflows.wordpress.com/2008/11/04/todays-the-day/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 08:49:30 +0000</pubDate>
		<dc:creator>Jari</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[politics]]></category>

		<guid isPermaLink="false">http://codeflows.wordpress.com/?p=67</guid>
		<description><![CDATA[
If I only could I would
  Change everything
Today is the day,
  the moment of reckoning

&#8212; Insomnium: &#8220;The Moment of Reckoning&#8221;
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflows.wordpress.com&blog=1742247&post=67&subd=codeflows&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><blockquote><p>
<em>If I only could I would<br />
  Change everything</em><br />
<em>Today is the day,<br />
  the moment of reckoning</em>
</p></blockquote>
<p>&#8212; Insomnium: <em>&#8220;The Moment of Reckoning&#8221;</em></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeflows.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeflows.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeflows.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeflows.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeflows.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeflows.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeflows.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeflows.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeflows.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeflows.wordpress.com/67/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflows.wordpress.com&blog=1742247&post=67&subd=codeflows&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://codeflows.wordpress.com/2008/11/04/todays-the-day/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">jari</media:title>
		</media:content>
	<feedburner:origLink>http://codeflows.wordpress.com/2008/11/04/todays-the-day/</feedburner:origLink></item>
		<item>
		<title>Learned me a Haskell</title>
		<link>http://feedproxy.google.com/~r/codeflows/~3/E4fXTNdg7R0/</link>
		<comments>http://codeflows.wordpress.com/2008/10/28/learned-me-a-haskell/#comments</comments>
		<pubDate>Tue, 28 Oct 2008 16:21:23 +0000</pubDate>
		<dc:creator>Jari</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[deadlock]]></category>
		<category><![CDATA[functional-programming]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[imperative-programming-is-so-2007]]></category>
		<category><![CDATA[parallel]]></category>
		<category><![CDATA[race-condition]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://codeflows.wordpress.com/?p=63</guid>
		<description><![CDATA[Learn You a Haskell for Great Good! is a cool little beginner&#8217;s guide to Haskell (reminiscent of the legendary Poignant Guide to Ruby) while Real World Haskell is an upcoming book from O&#8217;Reilly that&#8217;s freely available online (at least for now.)
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflows.wordpress.com&blog=1742247&post=63&subd=codeflows&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://learnyouahaskell.com/">Learn You a Haskell for Great Good!</a> is a cool little beginner&#8217;s guide to <a href="http://haskell.org/">Haskell</a> (reminiscent of the legendary <a href="http://poignantguide.net/ruby/">Poignant Guide to Ruby</a>) while <a href="http://book.realworldhaskell.org/">Real World Haskell</a> is an upcoming book from O&#8217;Reilly that&#8217;s freely available online (at least for now.)</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeflows.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeflows.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeflows.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeflows.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeflows.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeflows.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeflows.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeflows.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeflows.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeflows.wordpress.com/63/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflows.wordpress.com&blog=1742247&post=63&subd=codeflows&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://codeflows.wordpress.com/2008/10/28/learned-me-a-haskell/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">jari</media:title>
		</media:content>
	<feedburner:origLink>http://codeflows.wordpress.com/2008/10/28/learned-me-a-haskell/</feedburner:origLink></item>
		<item>
		<title>When the cup is both empty and full</title>
		<link>http://feedproxy.google.com/~r/codeflows/~3/wExtjnUYa2Q/</link>
		<comments>http://codeflows.wordpress.com/2008/10/26/when-the-cup-is-both-empty-and-full/#comments</comments>
		<pubDate>Sun, 26 Oct 2008 17:13:54 +0000</pubDate>
		<dc:creator>Jari</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bdd]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jdave]]></category>
		<category><![CDATA[jmock]]></category>
		<category><![CDATA[mock]]></category>
		<category><![CDATA[null object]]></category>
		<category><![CDATA[side-effects]]></category>

		<guid isPermaLink="false">http://codeflows.wordpress.com/?p=28</guid>
		<description><![CDATA[Last week, we had a spec mysteriously failing due to the following holding true:


!list.isEmpty() &#38;&#38; list.size() == 0

That is, I had a List instance that was both&#8230; non-empty and empty?
Turns out the failing spec was faulty to begin with, and a small refactoring that didn&#8217;t change any functionality but did change the way we communicated [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflows.wordpress.com&blog=1742247&post=28&subd=codeflows&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Last week, we had a <a href="http://jdave.org/">spec</a> mysteriously failing due to the following holding true:</p>
<pre name="code" class="java">

!list.isEmpty() &amp;&amp; list.size() == 0
</pre>
<p>That is, I had a <code>List</code> instance that was both&#8230; non-empty and empty?</p>
<p>Turns out the failing spec was faulty to begin with, and a small refactoring that didn&#8217;t change any functionality but did change the way we communicated with a certain API revealed this problem to us. The seemingly impossible state the <code>List</code> instance was in turned out to be a side-effect of setting up a too permissive mock object using <a href="http://jmock.org/">JMock</a>.</p>
<p>In JMock (and other libraries) you can explicitly state the mock interactions you care about and the ones you don&#8217;t. Let&#8217;s say you were implementing a user registration form for your website, and creating a new user would entail adding the user to the database using <code>DatabaseService</code> and subsequently sending an email containing the generated password using <code>EmailService</code>. Now, we clearly want to test that both of these things happen, but to make our specs as concise and isolated as possible, it&#8217;d be cool to test these expectations separately in their own spec methods. Enter JMock&#8217;s <code>ignoring</code> -construct, which enables you to state that you don&#8217;t care about the method calls a certain mock receives:</p>
<pre name="code" class="java">

...
class WhenUserRegistersSuccessfully {
  public void userIsAddedToTheDatabase() {
    checking(new Expectations() {{
      one(mockDatabaseService).save(expectedUserObject);
      ignoring(mockEmailService);
    }});
    fillFormAndSubmit();
  }

  public void passwordReminderMailIsSentToTheUser() {
    checking(new Expectations() {{
      ignoring(mockDatabaseService);
      one(mockEmailService).send(&quot;user@lolcats.com&quot;,
          &quot;Your password is &#039;secret&#039;&quot;);
    }});
    fillFormAndSubmit();
  }
}
...
</pre>
<p>Now, if we manage to break the interaction either with the database service or the email service, we get a clear indication of what the problem is. The scope is smaller than if we were to write a long test method packed with many assertions, in which case a failing test would &#8211; at a glance &#8211; only tell us that user registration is broken without immediately pointing out which part of it doesn&#8217;t work.</p>
<p>The side-effect of using <code>ignoring(...)</code> is that JMock <a href="http://jmock.org/ignoring.html">returns a default value for any method calls on the mock by default</a>. For methods with primitive return types, this is the default Java value for that type (zero for integers, false for booleans etc.) For methods that return Objects, JMock uses an <a href="http://www.jmock.org/javadoc/2.5.1/org/jmock/api/Imposteriser.html">imposteriser</a> to return a <a href="http://en.wikipedia.org/wiki/Null_Object_pattern">Null Object</a> of the desired type, which in turn returns default values for any methods called on it.</p>
<p>This leads us to why our spec started failing: the return values of a mock we had explicitly ignored were actually being used. A certain method returning a <code>List</code> returned a JMock-generated Null Object instead, and this returned the default values for both <code>isEmpty()</code> (false) and <code>size()</code> (zero.) Refactoring the code revealed that the scope of the spec wasn&#8217;t actually what we had thought it would be, and the rogue <code>List</code> had been used for real.</p>
<p>This goes to show that you should always keep your mocks and their expectations as strict as possible, and be aware of any side-effects using permissive mocks might have. Your code shouldn&#8217;t really touch the default values returned by ignored mocks: I&#8217;m not sure if JMock can be set up so that the Null Objects it returns for ignored methods would throw an exception if you called any method on them. This would certainly have saved us some time in this case.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeflows.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeflows.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeflows.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeflows.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeflows.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeflows.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeflows.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeflows.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeflows.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeflows.wordpress.com/28/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflows.wordpress.com&blog=1742247&post=28&subd=codeflows&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://codeflows.wordpress.com/2008/10/26/when-the-cup-is-both-empty-and-full/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">jari</media:title>
		</media:content>
	<feedburner:origLink>http://codeflows.wordpress.com/2008/10/26/when-the-cup-is-both-empty-and-full/</feedburner:origLink></item>
		<item>
		<title>Ping?</title>
		<link>http://feedproxy.google.com/~r/codeflows/~3/E87_9XiXjN8/</link>
		<comments>http://codeflows.wordpress.com/2008/06/18/ping/#comments</comments>
		<pubDate>Wed, 18 Jun 2008 19:27:57 +0000</pubDate>
		<dc:creator>Jari</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[embreach]]></category>
		<category><![CDATA[life]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://codeflows.wordpress.com/?p=25</guid>
		<description><![CDATA[Long time no post. Working instead of studying for the first time in a long while. Expect more activity here.
Apart from work, our new promo album is keeping me busy (yes, the studio blog has the same theme as this one, but hey, it&#8217;s the best looking one available at wordpress.com.)
     [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflows.wordpress.com&blog=1742247&post=25&subd=codeflows&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Long time no post. Working instead of studying for the first time in a long while. Expect more activity here.</p>
<p>Apart from work, <a href="http://embreach.wordpress.com/">our new promo album is keeping me busy</a> (yes, the studio blog has the same theme as this one, but hey, it&#8217;s the best looking one available at wordpress.com.)</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/codeflows.wordpress.com/25/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/codeflows.wordpress.com/25/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeflows.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeflows.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeflows.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeflows.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeflows.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeflows.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeflows.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeflows.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeflows.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeflows.wordpress.com/25/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflows.wordpress.com&blog=1742247&post=25&subd=codeflows&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://codeflows.wordpress.com/2008/06/18/ping/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">jari</media:title>
		</media:content>
	<feedburner:origLink>http://codeflows.wordpress.com/2008/06/18/ping/</feedburner:origLink></item>
		<item>
		<title>A recipe for disaster</title>
		<link>http://feedproxy.google.com/~r/codeflows/~3/1EutaXZjFbg/</link>
		<comments>http://codeflows.wordpress.com/2007/12/23/a-recipe-for-disaster/#comments</comments>
		<pubDate>Sun, 23 Dec 2007 10:03:57 +0000</pubDate>
		<dc:creator>Jari</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[destruction]]></category>
		<category><![CDATA[macbook]]></category>

		<guid isPermaLink="false">http://codeflows.wordpress.com/2007/12/23/a-recipe-for-disaster/</guid>
		<description><![CDATA[
1 MacBook
0,5 liter of a sugary liquid of your choice



Mix the ingredients. Season to taste. Witness how fixing a 1000e computer can cost over 1300e. Be thankful for a good home insurance plan.
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflows.wordpress.com&blog=1742247&post=24&subd=codeflows&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><ul>
<li>1 MacBook</li>
<li>0,5 liter of a sugary liquid of your choice</li>
</ul>
<p></p>
<p>
Mix the ingredients. Season to taste. Witness how fixing a 1000e computer can cost over 1300e. Be thankful for a good home insurance plan.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/codeflows.wordpress.com/24/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/codeflows.wordpress.com/24/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeflows.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeflows.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeflows.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeflows.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeflows.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeflows.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeflows.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeflows.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeflows.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeflows.wordpress.com/24/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflows.wordpress.com&blog=1742247&post=24&subd=codeflows&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://codeflows.wordpress.com/2007/12/23/a-recipe-for-disaster/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">jari</media:title>
		</media:content>
	<feedburner:origLink>http://codeflows.wordpress.com/2007/12/23/a-recipe-for-disaster/</feedburner:origLink></item>
		<item>
		<title>Implicit fun</title>
		<link>http://feedproxy.google.com/~r/codeflows/~3/qSH8GwfmCAI/</link>
		<comments>http://codeflows.wordpress.com/2007/12/13/implicit-fun/#comments</comments>
		<pubDate>Thu, 13 Dec 2007 11:23:44 +0000</pubDate>
		<dc:creator>Jari</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bdd]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://codeflows.wordpress.com/2007/12/13/implicit-fun/</guid>
		<description><![CDATA[I&#8217;ve been delving into Scala quite a bit the last couple of weeks. Coderspiel has a piece on one of the coolest features in Scala: implicit type conversions.
In theory, these conversions allow you to use an object of type X in an expression where an object of type Y is expected. To achieve this, you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflows.wordpress.com&blog=1742247&post=23&subd=codeflows&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;ve been delving into Scala quite a bit the last couple of weeks. <a href="http://technically.us/code/x/the-awesomeness-of-scala-is-implicit">Coderspiel</a> has a piece on one of the coolest features in Scala: <em>implicit type conversions.</em></p>
<p>In theory, these conversions allow you to use an object of type X in an expression where an object of type Y is expected. To achieve this, you define <em>an implicit conversion function</em> that takes an <b>X</b> and returns a <b>Y</b> (<em>f: X -&gt; Y</em> for the mathematically inclined), and tag it with the language keyword <em>implicit</em>. Now, Scala can implicitly (and transparently to you, the coder) convert X&#8217;s to Y&#8217;s, if needed. Consider an example:</p>
<blockquote>
<pre>
class Apple

class Orange {
  def hi = Console.println("Hi, orange!")
}

object ApplesToOranges extends Application {
  // This is our type conversion function.
  // Note that its name can be ANYTHING:
  //   only the type signature matters!
  implicit def applesToOranges(a: Apple) : Orange = new Orange

  val a = new Apple()

  // the implicit conversion occurs here, as Apple
  // doesn't have a method called "hi", but Orange
  // does, and we have defined the implicit conversion
  // from Apples to Oranges
  a.hi
}
</pre>
</blockquote>
<p>This example doesn&#8217;t make much sense, but shows you the mechanics of implicit conversions. In practice, implicit conversions allow you to do some seriously cool things, such as extending existing Java class libraries (check out the Coderspiel entry for the JDBC and Wicket examples) elegantly.</p>
<p>There&#8217;s more to implicit type conversions than merely forcing legacy code to behave, though. For example, now that we can convert objects between different types pretty much arbitrarily and transparently, some <a href="http://en.wikipedia.org/wiki/Domain-specific_programming_language">DSL</a>-like constructs become easier. Consider the <a href="http://rspec.rubyforge.org/">RSpec</a> -style assertions found in many <a href="http://en.wikipedia.org/wiki/Behavior_driven_development">BDD</a> frameworks:</p>
<blockquote>
<pre>
product.price.should == 5
character.name.should == "Mudkip"
</pre>
</blockquote>
<p>Now, these clearly boil down to the format of</p>
<blockquote>
<pre>
(some expression) should (expectation)
</pre>
</blockquote>
<p>Perhaps we could represent these expectations using a class called <em>Expectation</em>, and have it evaluate any conditions thrown at it. Since we want to be able to say <em>should</em> for any object whatsoever, we need an implicit conversion from any type to an Expectation. Drum roll, please:</p>
<blockquote>
<pre>
case class Thing(name: String)

object Expectations extends Application with Specification {
  val mudkip = new Thing("mudkip")
  mudkip.name should equal("mudkip")

  (2 * 3) should equal(6)

  // BOOM: failure!
  false should equal(true)
}

// quick and dirty implementation
// just to illustrate the mechanics

class Expectation[T](value: T) {
  def should(eq: Equality[T]) = {
    if(value != eq.value) {
      throw new AssertionError(
        "Expected " + eq.value + " but was " + value
      )
    }
  }
}

case class Equality[T](value: T)

trait Specification {
  implicit def anythingToExpectation[T](value: T)
    = new Expectation[T](value)

  def equal[T](t: T) = new Equality[T](t)
}
</pre>
</blockquote>
<p><a href="http://code.google.com/p/specs/">Specs</a>, a BDD framework for Scala, seems to utilize implicit conversions in this manner to support a pretty concise way of writing specifications.</p>
<p>So, in inaccurate yet nerd-appealing terms, implicit type conversions are sort of like having the power of Ruby&#8217;s open classes in a statically typed language &#8211; <a href="http://en.wikipedia.org/wiki/Monkey_patch">monkey patching</a>, wicked! Don&#8217;t over-use &#8216;em, though: you might hit issues such as ambiguity between different conversions (though the conversion functions <em>are</em> scoped.) As open classes, they seem like a prime candidate for the &#8220;I don&#8217;t know what I&#8217;m doing but if I stick this here, it seems to work&#8221; -type of coding.</p>
<p>Btw, the PDF version of the forthcoming book on Scala, aptly named <a href="http://www.artima.com/shop/forsale">Programming in Scala</a>, is available through Artima&#8217;s early access program.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/codeflows.wordpress.com/23/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/codeflows.wordpress.com/23/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeflows.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeflows.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeflows.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeflows.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeflows.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeflows.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeflows.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeflows.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeflows.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeflows.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflows.wordpress.com&blog=1742247&post=23&subd=codeflows&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://codeflows.wordpress.com/2007/12/13/implicit-fun/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">jari</media:title>
		</media:content>
	<feedburner:origLink>http://codeflows.wordpress.com/2007/12/13/implicit-fun/</feedburner:origLink></item>
		<item>
		<title>RubyConf 2007 presentations online</title>
		<link>http://feedproxy.google.com/~r/codeflows/~3/1jFOFCMi5Qk/</link>
		<comments>http://codeflows.wordpress.com/2007/12/11/rubyconf-2007-presentations-online/#comments</comments>
		<pubDate>Tue, 11 Dec 2007 21:15:01 +0000</pubDate>
		<dc:creator>Jari</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[parser]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://codeflows.wordpress.com/2007/12/11/rubyconf-2007-presentations-online/</guid>
		<description><![CDATA[Courtesy of Confreaks. Good stuff. Currently watching the presentation on Treetop, a DSL-based parser framework for Ruby.
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflows.wordpress.com&blog=1742247&post=22&subd=codeflows&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://rubyconf2007.confreaks.com/">Courtesy of Confreaks</a>. Good stuff. Currently watching <a href="http://rubyconf2007.confreaks.com/d1t1p5_treetop.html">the presentation on Treetop</a>, a DSL-based parser framework for Ruby.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/codeflows.wordpress.com/22/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/codeflows.wordpress.com/22/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeflows.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeflows.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeflows.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeflows.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeflows.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeflows.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeflows.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeflows.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeflows.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeflows.wordpress.com/22/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflows.wordpress.com&blog=1742247&post=22&subd=codeflows&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://codeflows.wordpress.com/2007/12/11/rubyconf-2007-presentations-online/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">jari</media:title>
		</media:content>
	<feedburner:origLink>http://codeflows.wordpress.com/2007/12/11/rubyconf-2007-presentations-online/</feedburner:origLink></item>
		<item>
		<title>Joel on quality</title>
		<link>http://feedproxy.google.com/~r/codeflows/~3/ZLu-IfJWO84/</link>
		<comments>http://codeflows.wordpress.com/2007/12/04/joel-on-quality/#comments</comments>
		<pubDate>Tue, 04 Dec 2007 11:56:52 +0000</pubDate>
		<dc:creator>Jari</dc:creator>
				<category><![CDATA[thesis]]></category>
		<category><![CDATA[qa]]></category>
		<category><![CDATA[quality]]></category>

		<guid isPermaLink="false">http://codeflows.wordpress.com/2007/12/04/joel-on-quality/</guid>
		<description><![CDATA[Joel Spolsky&#8217;s recent talk at Yale has some interesting bits on software quality.
He claims that über-geeks tend to focus on defining quality strictly as conforming to requirements (à la Crosby), and thus try to write automated specs for the whole program. Now, trying to write complete specs becomes the &#8220;software engineering equivalent of a perpetual [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflows.wordpress.com&blog=1742247&post=21&subd=codeflows&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Joel Spolsky&#8217;s <a href="http://www.joelonsoftware.com/items/2007/12/03.html">recent talk at Yale</a> has some interesting bits on software quality.</p>
<p>He claims that über-geeks tend to focus on defining quality strictly as conforming to requirements (<a href="http://en.wikipedia.org/wiki/Phil_Crosby">à la Crosby</a>), and thus try to write automated specs for the whole program. Now, trying to write complete specs becomes the <em>&#8220;software engineering equivalent of a perpetual motion machine&#8221;</em>, since if your specs are complete, they describe the whole program accurately, and could be thus used to generate the actual program somehow &#8211; after all, your specs will end up being as detailed as the program itself. (btw, I love any blog entry with the terms &#8220;perpetual motion machine&#8221; and &#8220;crackpot&#8221; in it)</p>
<p>Naturally, the concept of &#8220;complete specs&#8221; is unrealistic and is there just for the argument&#8217;s sake (let&#8217;s just strive for &#8220;enough specs&#8221; instead.) Also, any sane definition of software quality goes beyond &#8220;literally adhering to specs.&#8221; Different stakeholders have different perspectives on quality. General product quality concepts that originate from the manufacturing industry tend to view specifications as the producer&#8217;s &#8220;path to victory.&#8221; Adhering to them should be enough to produce a high-quality product &#8211; from the manufacturer&#8217;s point of view. The value perceived by customer can be different, and consists of different attributes such as price, performance and reliability. The ultimate validation of quality is always customer satisfaction.</p>
<p>Although all generic product quality concepts don&#8217;t necessarily translate to software quality, there are recurrent themes on both sides: customer is king!</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/codeflows.wordpress.com/21/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/codeflows.wordpress.com/21/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeflows.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeflows.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeflows.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeflows.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeflows.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeflows.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeflows.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeflows.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeflows.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeflows.wordpress.com/21/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflows.wordpress.com&blog=1742247&post=21&subd=codeflows&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://codeflows.wordpress.com/2007/12/04/joel-on-quality/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">jari</media:title>
		</media:content>
	<feedburner:origLink>http://codeflows.wordpress.com/2007/12/04/joel-on-quality/</feedburner:origLink></item>
		<item>
		<title>On type inference and redundant type declarations</title>
		<link>http://feedproxy.google.com/~r/codeflows/~3/qERr21UeBbs/</link>
		<comments>http://codeflows.wordpress.com/2007/11/06/on-type-inference-and-redundant-type-declarations/#comments</comments>
		<pubDate>Tue, 06 Nov 2007 19:47:22 +0000</pubDate>
		<dc:creator>Jari</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[compilers]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[static-typing]]></category>
		<category><![CDATA[type-inference]]></category>

		<guid isPermaLink="false">http://codeflows.wordpress.com/2007/11/06/on-type-inference-and-redundant-type-declarations/</guid>
		<description><![CDATA[Stephan Schmidt has a blog entry on how explicit static type declarations are for the benefit of the developer, and not the compiler. That is, when you have something like this:
Person person = mysteriousCall()
you know at a glance that the object reference person is in fact of type Person. To a compiler, this might be [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflows.wordpress.com&blog=1742247&post=20&subd=codeflows&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://stephan.reposita.org/archives/2007/11/05/explicit-static-types-are-not-for-the-compiler-but-for-the-developer-duh/">Stephan Schmidt has a blog entry</a> on how explicit static type declarations are for the benefit of the developer, and not the compiler. That is, when you have something like this:</p>
<blockquote><p>Person person = mysteriousCall()</p></blockquote>
<p>you know at a glance that the object reference <code>person</code> is in fact of type <code>Person</code>. To a compiler, this might be obvious through <em>type inference</em> &#8211; in this case, by looking at the return type of the <code>mysteriousCall</code> function.</p>
<p>In Java, you always declare the member types explicitly, but for a statically typed language that does rely on type inference (I&#8217;m thinking <a href="http://www.scala-lang.org/">Scala</a>), the type declaration <code>Person</code> is clearly redundant. And if there&#8217;s one thing any programmer hates, it&#8217;s redundancy. So, one could just go with</p>
<blockquote><p>val person = mysteriousCall()</p></blockquote>
<p>and be done with it: the compiler will infer the type. Now, Schmidt makes a good point in that now the type of <code>person</code> is not immediately obvious to the naked eye, since there&#8217;s no explicit declaration in sight. This gave me an idea, which I posted as a comment to the blog entry:</p>
<p>What if a smart IDE could consult the compiler and decorate / annotate the above code line visually by showing the type of the <code>person</code> field? Now, the type would be explicitly shown to the user, but information that&#8217;s available through type inference wouldn&#8217;t have to be duplicated in the actual code.</p>
<p>Something like</p>
<blockquote><p>
val person <span style="background-color:#f00;color:#fff;padding:3px;">: Person</span> = mysteriousCall()
</p></blockquote>
<p>where <code>: Person</code> is the visual aid shown by the IDE, in standard Scala type declaration notation. Now, the type of the value is clearly visible, but there are no redundant type declarations in the code.</p>
<p>I wonder if anyone&#8217;s thought of this before (likely), and whether some tool already implements this for some language with type inference (less likely)?</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/codeflows.wordpress.com/20/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/codeflows.wordpress.com/20/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeflows.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeflows.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeflows.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeflows.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeflows.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeflows.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeflows.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeflows.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeflows.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeflows.wordpress.com/20/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflows.wordpress.com&blog=1742247&post=20&subd=codeflows&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://codeflows.wordpress.com/2007/11/06/on-type-inference-and-redundant-type-declarations/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">jari</media:title>
		</media:content>
	<feedburner:origLink>http://codeflows.wordpress.com/2007/11/06/on-type-inference-and-redundant-type-declarations/</feedburner:origLink></item>
	</channel>
</rss>
