<?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/"
	>

<channel>
	<title>Xebia Blog &#187; Jan Vermeir</title>
	<atom:link href="http://blog.xebia.com/author/jvermeir/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.xebia.com</link>
	<description>Software development done right!</description>
	<lastBuildDate>Wed, 01 Feb 2012 00:30:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Getting the Java out of your Scala, part 2</title>
		<link>http://blog.xebia.com/2011/11/12/getting-the-java-out-of-your-scala-part-2/</link>
		<comments>http://blog.xebia.com/2011/11/12/getting-the-java-out-of-your-scala-part-2/#comments</comments>
		<pubDate>Sat, 12 Nov 2011 17:09:36 +0000</pubDate>
		<dc:creator>Jan Vermeir</dc:creator>
				<category><![CDATA[Scala]]></category>

	<!-- AutoMeta Start -->
	<category>stuffs</category>
	<category>groupedbylabel</category>
	<category>groupby</category>
	<category>expectedresult</category>
	<category>mapvalues</category>
	<category>currenthead</category>
	<category>shoppinglist</category>
	<category>resultgroupedbylabel</category>
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://blog.xebia.com/?p=7998</guid>
		<description><![CDATA[Getting the Java out of your Scala, part 2 I’m still trying to get rid of old habits, to shake of my winter hide, so to speak, and create some real Scala in stead of ScaVa (i.e. Java with a Scala syntax). If you’re interested you can bear witness to my struggle on GitHub (ShoppingList [...]]]></description>
			<content:encoded><![CDATA[<p>Getting the Java out of your Scala, part 2</p>
<p>I’m still trying to get rid of old habits, to shake of my winter hide, so to speak, and create some real Scala in stead of ScaVa (i.e. Java with a Scala syntax). If you’re interested you can bear witness to my struggle on GitHub (<a href='https://github.com/jvermeir/ShoppingList'>ShoppingList on GitHub</a>). This story came about because I asked some colleagues for help. We ended up rewriting loops in several ways.<br />
What I’ll show you is some alternatives to classic loops over collections.<br />
<span id="more-7998"></span></p>
<p>The code <a href='http://blog.xebia.com/wp-content/uploads/2011/11/SumByGroup.txt'>is attached here</a>. The example shows how to summarize items in a list. The objects in the list are all instances of class Stuff, a simple value container for a String and an Int. The idea is to summarize Stuffs with the same key to produce a new list:</p>
<pre class="brush: scala; title: ; notranslate">
  val items = List(Stuff(&quot;A&quot;, 1), Stuff(&quot;A&quot;, 2), Stuff(&quot;B&quot;, 3), Stuff(&quot;B&quot;, 4))
</pre>
<p>should become</p>
<pre class="brush: scala; title: ; notranslate">
  val expectedResult = List(Stuff(&quot;A&quot;, 3), Stuff(&quot;B&quot;, 7))
</pre>
<p>where Stuff is a simple case class with two attributes:</p>
<pre class="brush: scala; title: ; notranslate">
case class Stuff(val label: String, val number: Int)
</pre>
<p>Because I’m a long time Java programmer, my first solution looks like this:</p>
<pre class="brush: scala; title: ; notranslate">
  def classicSum = {
    var result: List[Stuff] = List()
    for (item &lt;- items) {
      if (result.size &gt; 0 &amp;&amp; item.label == result.head.label) {
        result = Stuff(result.head.label, result.head.number + item.number) :: result.drop(1)
      } else {
        result = item :: result
      }
    }
    assertEquals(expectedResult, result.reverse)
  }
 </pre>
<p>Good old looping and a var to collect the result. This works, but it doesn’t say what’s happening. All you see is a loop and some fancy list processing. Note the call to drop(1) allowing you to replace the head of the list with a new instance. I like the drop function and I’ve used it in other programs but here it just obfuscates matters.</p>
<p>The next solution is to go recursive. If you check out the version of ShoppingList as of October/November 2011, you’ll find lots of recursion. My goal at the time was to jam recursion into my head by banning all other forms of looping.<br />
Applied to the list of Stuff instances and the problem at hand, the result is tragic:</p>
<pre class="brush: scala; title: ; notranslate">
  def recursiveSum = {
    @tailrec def sum(listOfPairs: List[Stuff], result: List[Stuff]): List[Stuff] = {
      listOfPairs match {
        case Nil =&gt; result
        case head :: tail =&gt;
          {
            val currentHead = if (result.size == 0) { Stuff(head.label, 0) } else { result.head }
            val newResult =
              if (currentHead.label == head.label) {
                Stuff(currentHead.label, currentHead.number + head.number) :: result.drop(1)
              } else { head :: result }
            sum(tail, newResult)
          }
      }
    }
    val result = sum(items, List())
    assertEquals(expectedResult, result.reverse)
  }
 </pre>
<p>My next version leverages Scala’s collections to drastically reduce the amount of code. The first attempt passes the test but it is cryptic. In the spirit of the red-green-refactor mantra I’ll show it to you anyway:</p>
<pre class="brush: scala; title: ; notranslate">
  def sumByGroupSolution1 = {
    val groupedByLabel = items.groupBy(_.label)
    val result = groupedByLabel map { t =&gt; Stuff(t._1, t._2 map { _.number } sum) }
    assertEquals(expectedResult, result)
  }
 </pre>
<p>There! Go and parse that if you need to change this code sometime next year (note: having worked with this code for some time now while writing this blog, I must admit that it grows on you; after a while it doesn’t hurt all that much, sort of like a new pair of shoes). This cryptic piece of mal-ware illustrates the use of three powerfull methods named groupBy, map and sum.<br />
groupBy is in a sense comparable to SQLs group by clause. The Scala version takes a collection and returns a Map. The map’s key is the element used to group by (Stuff.label in my case). The value is a List of elements that have the same key. In this case the items collection contains Stuff instances. I’ve grouped by the label field so the type of groupedByLabel is Map[String, List[Stuff]]. On this Map we have to apply a sum function to add up all Stuff instances in the List of Stuffs. Sum however works on Int’s, so before sum can be applied we have to extract the number field of each Stuff instance. This is done by a map: map {_.number}. The mapping is applied to each Stuff instance in the list of Stuffs that was returned by groupedByLabel. </p>
<p>By factoring out part of the code on line 3 in the example above, we can improve readability: </p>
<pre class="brush: scala; title: ; notranslate">
  def sumByGroupSolution2 = {
	val stuffsGroupedByLabel = items.groupBy(_.label)
    def sumOfStuffsWithTheSameLabel(stuffs: List[Stuff]): Int = stuffs map { _.number } sum
    val result = stuffsGroupedByLabel map { t =&gt; Stuff(t._1, sumOfStuffsWithTheSameLabel(t._2)) }
    assertEquals(expectedResult, result)
  }
 </pre>
<p>I think this is better because now the result of part of the computation is named. Naming a thing makes it easier to see the algorithm.</p>
<p>The next solution uses more intermediate results. The results of each map or sum operation are stored in a variable that gets a meaningful name. This clarifies the meaning of intermediate results but the amount of code grows.</p>
<pre class="brush: scala; title: ; notranslate">
  @Test
  def sumByGroupSolution5 = {
    val calcSumOfStuff = (stuffs: Seq[Stuff]) =&gt; stuffs map { _.number } sum
    val groupedByLabel = items.groupBy { _.label }
    val resultGroupedByLabel = groupedByLabel mapValues { calcSumOfStuff }
    val result = resultGroupedByLabel map { t =&gt; Stuff(t._1, t._2) }
    assertEquals(expectedResult, result)
  }
</pre>
<p>The code shows another Map function named mapValues. </p>
<pre class="brush: scala; title: ; notranslate">
 val resultGroupedByLabel = groupedByLabel mapValues { calcSumOfStuff }
</pre>
<p>mapValues works on the values of a map only, ignoring the keys. In my case the keys don’t really matter (they’re an artifact of the groupBy call) so I can get away with mapValues rather than map.</p>
<p>Naming things was also the inspiration for the next solution. Now I’m not extracting intermediate results but in this case I’ve named the variables being manipulated:</p>
<pre class="brush: scala; title: ; notranslate">
  def sumByGroupSolution4 = {
    val groupedByLabel = items.groupBy(_.label)
    val result = groupedByLabel map { case (label, stuffs) =&gt; Stuff(label, stuffs map { _.number } sum) }
    assertEquals(expectedResult, result)
  }
</pre>
<p>The case statement as argument to the map makes it possible to introduce two variables to identify the things we’re manipulating. Label and stuffs mean more to me than _1 and _2. </p>
<p>Looking back on my struggle I like this solution best. I think it is both concise and easy to read. </p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="small" count="1" href="http://blog.xebia.com/2011/11/12/getting-the-java-out-of-your-scala-part-2/"></g:plusone></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.xebia.com%2F2011%2F11%2F12%2Fgetting-the-java-out-of-your-scala-part-2%2F&amp;title=Getting%20the%20Java%20out%20of%20your%20Scala%2C%20part%202" id="wpa2a_2"><img src="http://blog.xebia.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.xebia.com/2011/11/12/getting-the-java-out-of-your-scala-part-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>First steps in Android</title>
		<link>http://blog.xebia.com/2011/09/13/first-steps-in-android/</link>
		<comments>http://blog.xebia.com/2011/09/13/first-steps-in-android/#comments</comments>
		<pubDate>Tue, 13 Sep 2011 17:51:14 +0000</pubDate>
		<dc:creator>Jan Vermeir</dc:creator>
				<category><![CDATA[android]]></category>
		<category><![CDATA[mobile]]></category>

	<!-- AutoMeta Start -->
	<category>quizlist</category>
	<category>quizzz</category>
	<category>oncreate</category>
	<category>android</category>
	<category>fromassetsdirectory</category>
	<category>bird</category>
	<category>birds</category>
	<category>savedinstancestate</category>
	<category>quizlist</category>
	<category>quizzz</category>
	<category>oncreate</category>
	<category>android</category>
	<category>fromassetsdirectory</category>
	<category>bird</category>
	<category>birds</category>
	<category>savedinstancestate</category>
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://blog.xebia.com/?p=7484</guid>
		<description><![CDATA[With everybody going mobile, we could not stay behind. This meant we had to create an Android application, because we (Bram Neijt, Arno den Hond and your chronicler) do not own one of them fancy iPhones. Also, Android is way cooler. To begin our journey to become Android developers, we decided to create Quizzz: an [...]]]></description>
			<content:encoded><![CDATA[<p>With everybody going mobile, we could not stay behind. This meant we had to create an Android application, because we (Bram Neijt, Arno den Hond and your chronicler) do not own one of them fancy iPhones.<br />
Also, Android is way cooler.<br />
<span id="more-7484"></span><br />
To begin our journey to become Android developers, we decided to create Quizzz: an app to help you learn the names of your colleagues. Because we felt a little uncomfortable putting everyone&#8217;s picture in the Android appstore, we decided to use pictures of animals instead. <a href="http://en.wikipedia.org/wiki/List_of_birds_of_India">Indian birds</a> in this case to emphasize our connection with our Indian colleagues. This would give us a simple application that would require only a small subset of the Android API. We also wanted to familiarize ourselves with the Android development cycle<br />
from interaction design to development, testing, and deployment.</p>
<p>After installing the <a href="http://developer.android.com/index.html">Android development</a> environment we where faced with the problem of designing our application.</p>
<p><strong>Design</strong><br />
The idea of Quizzz is to show a screen with a picture, from our Xebia face book originally but for now a picture of a bird, and then provide the user with three names to choose from. On a white board it looks like this:</p>
<p><a href="http://blog.xebia.com/wp-content/uploads/2011/09/sketch.png"><img class="alignnone size-medium wp-image-7487" title="sketch" src="http://blog.xebia.com/wp-content/uploads/2011/09/sketch-259x300.png" alt="" width="259" height="300" /></a><br />
The top left part shows the starting screen: three buttons with random names, one of which is the name of the bird shown in the picture above. If you choose the correct name, you end up in the top right screen. If you press the wrong button, you end up in the lower right screen which shows you the correct answer and a button that takes you to<br />
the top right screen where you can see the picture and name of the bird you selected.</p>
<p>We decided to implement the application as a single Activity. Activities are subsets of an application which can combine into a workflow by going from one activity to another. The back button on the phone takes you to the previous activity (not necessarily the previous content of the screen) so Activities structure the way the user navigates through the app. Because there is no back functionality in our application, we decided to create the whole workflow in one Activity. We use layout switching to present the user with different screens. This isn&#8217;t true in general, of course. In later versions we&#8217;ll add more Activities and Intentions and such, but for now we&#8217;ll keep things simple.</p>
<p><strong>Code</strong><br />
To download the code, visit <a href="http://github.com/xebia/quizzz">http://github.com/xebia/quizzz</a> or clone the<br />
repository:</p>
<pre class="brush: plain; title: ; notranslate">
git clone https://github.com/xebia/quizzz
cd quizzz
git checkout release1.0
</pre>
<p>We defined two layouts, main.xml and result.xml. The first shows the left side of the design and the second the right part of the design (see picture below).</p>
<p><img class="alignnone size-medium wp-image-7492" title="screens" src="http://blog.xebia.com/wp-content/uploads/2011/09/Screen-Shot-2011-09-13-at-8.22.16-PM-195x300.png" alt="screens" width="195" height="300" /></p>
<p>If you start the app, QuizActivity is started. The Android framework calls the onCreate() method to do the required initialization. In our case this includes loading a set of images from a directory. We choose a list of birds common to India as a sample set, but any set of pictures will do.</p>
<pre class="brush: java; title: ; notranslate">	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		quizSet = QuizList.fromAssetsDirectory(this, &quot;sets/Birds of India&quot;);
		layoutQuestion();
	}
</pre>
<p>The set of pictures for the quiz is loaded by a helper class named QuizList. The fromAssetsDirectory used the Android platform to load image files from a directory called &#8216;assets&#8217; in the root of the quizzz project. The list is static now because it gets deployed along with the application. We will change that in a future version.</p>
<pre class="brush: java; title: ; notranslate">   public static QuizList fromAssetsDirectory(Context context, String directory) {
        QuizList quizList = new QuizList();
        try {
            String[] list = context.getResources().getAssets().list(directory);
            for (String pictureAssetName : list) {
                quizList.add(new AssetQuizItem(directory + &quot;/&quot; + pictureAssetName));
            }
        } catch (IOException e) {
            //Empty quizset
        }
        return quizList;
    }
</pre>
<p>The last act of onCreate() is to call layoutQuestion(). This method randomly selects three images from the set loaded before, assigns them to buttons and then hooks up itself in the setOnClickListener() method of each button. The buttons are stored in a HashMap so they can be retrieved later in the onClick() method.</p>
<p>onClick() uses the clicked button as an index in the HashMap mentioned above to find the answer that was chosen by the users and delegates to either layoutIfAnswerIsCorrect() or layoutIfAnswerIsWrong(). Both methods fill in data on a new view based on the answer supplied by the user. The methods end with a block of code that sets up a new Button and a listener to allow the user to take the next step.</p>
<p>Now the app sits and waits for a button to be pressed. Once this happens, the button&#8217;s onClickListener() method is executed. This causes onClick() to be called and the app takes appropriate action based on the user&#8217;s selection.</p>
<p>Note that we haven&#8217;t implemented other Activity life cycle methods (onPause(), onStop() and onDestroy()). We&#8217;re leaving this for later.</p>
<p><strong>Result</strong><br />
To test our work we used the emulator in Eclipse. Right-click (or double-tap) the quizzz project in Eclipse and select RunAs -&gt; Android application. Starting the emulator can be slow at times (it seems to use only a single core, this is a touch to realistic in our opinion&#8230;) but once started it is fast enough.</p>
<p>Deploying on your phone takes only a little longer. Choose Export -&gt; Android -&gt; Android Application and follow the steps of the wizard.</p>
<p>One thing that took a while to figure out: how to make a screen shot of the desktop of your phone? It turns out there is a function for that: hold down the back button and then press the button next to it.<br />
Android confirms a screen shot has been taken and stores the image in the ScreenCapture directory.</p>
<p><strong>Next steps</strong><br />
Now the basics work, we plan to explore further by adding the following functions (list is in no particular order):</p>
<ol>
<li>Add an options button to load a set of pictures (so we can have the colleague quiz after all).</li>
<li>Implement all life cycle methods.</li>
<li>Build the app with Maven.</li>
<li>Find out how to unit/integration test Android</li>
</ol>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="small" count="1" href="http://blog.xebia.com/2011/09/13/first-steps-in-android/"></g:plusone></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.xebia.com%2F2011%2F09%2F13%2Ffirst-steps-in-android%2F&amp;title=First%20steps%20in%20Android" id="wpa2a_4"><img src="http://blog.xebia.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.xebia.com/2011/09/13/first-steps-in-android/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting the Java out of your Scala</title>
		<link>http://blog.xebia.com/2011/04/03/getting-the-java-out-of-your-scala/</link>
		<comments>http://blog.xebia.com/2011/04/03/getting-the-java-out-of-your-scala/#comments</comments>
		<pubDate>Sun, 03 Apr 2011 15:24:39 +0000</pubDate>
		<dc:creator>Jan Vermeir</dc:creator>
				<category><![CDATA[Scala]]></category>

	<!-- AutoMeta Start -->
	<category>configdata</category>
	<category>jmsobjects</category>
	<category>elem</category>
	<category>parsing</category>
	<category>jmsobject</category>
	<category>jmsconfigfilename</category>
	<category>queue</category>
	<category>scala</category>
	<category>configdata</category>
	<category>jmsobjects</category>
	<category>elem</category>
	<category>parsing</category>
	<category>jmsobject</category>
	<category>jmsconfigfilename</category>
	<category>queue</category>
	<category>scala</category>
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://blog.xebia.com/?p=6620</guid>
		<description><![CDATA[To get some grip on the configuration of the Weblogic domains and servers at my current client, I created a tool that reads domain config files and translates them in a graph. I decided to solve this problem in Scala, mainly because I read about its powerful native XML parsing capabilities. Parsing XML turned out [...]]]></description>
			<content:encoded><![CDATA[<p>To get some grip on the configuration of the Weblogic domains and servers at my current client, I created a tool that reads domain config files and translates them in a graph. I decided to solve this problem in Scala, mainly because I read about its powerful native XML parsing capabilities. Parsing XML turned out to be a total no-brainer, but I managed to learn something about how to solve problems the Scala way, so this is a story about Scala rather than parsing XML in Scala.<br />
<span id="more-6620"></span><br />
To solve my problem I had to parse the configuration file for a Weblogic domain, or more specifically (in my case) the file where Weblogic stores information about JMS resources. Parsing one of those files is done like this:</p>
<pre class="brush: scala; title: ; notranslate">
    val configData: Elem = XML.loadFile(jmsConfigFileName)
</pre>
<p>configData now holds a parsed version of the file whose name is stored in jmsConfigFileName. This file contains stuff like queue and topic definitions like the fragment below:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;queue name=&quot;queueTo&quot;&gt;
    &lt;sub-deployment-name&gt;domain&lt;/sub-deployment-name&gt;
    &lt;jndi-name&gt;domain/jms/qto&lt;/jndi-name&gt;
  &lt;/queue&gt;
  &lt;topic name=&quot;domainJMSTopic&quot;&gt;
    &lt;sub-deployment-name&gt;domain&lt;/sub-deployment-name&gt;
    &lt;jndi-name&gt;domain/jms/topic&lt;/jndi-name&gt;
  &lt;/topic&gt;
</pre>
<p>My first attempt at retrieving all topic definitions from this config file was this:</p>
<pre class="brush: scala; title: ; notranslate">
  def findTopics(configData: Elem): Set[JmsObject] = {
    val jmsObjects = for (topic &lt;- (configData \\ &quot;topic&quot;))
      yield (new JmsTopic((topic \ &quot;@name&quot;).text, (topic \ &quot;jndi-name&quot;).text))
    jmsObjects.toSet
  }
</pre>
<p>I felt really happy about having written this powerful and concise loop. Scala&#8217;s for construct is powerful, as well as its XML parsing. To retrieve the queues I added the method below:</p>
<pre class="brush: scala; title: ; notranslate">
  def findQueues(configData: Elem): Set[JmsObject] = {
    val jmsObjects = for (queue &lt;- (configData \\ &quot;queue&quot;))
      yield (new JmsQueue((queue \ &quot;@name&quot;).text, (queue \ &quot;jndi-name&quot;).text))
    jmsObjects.toSet
  }
</pre>
<p>The duplication was obvious, so I felt a little less happy with my solution but I couldn&#8217;t see an easy way out. Enter my colleague and Scala trainer Urs Peter. He showed me two ways to improve the code.<br />
Our first attempt looks like this:</p>
<pre class="brush: scala; title: ; notranslate">
def buildListOfJmsObjectsFromConfigData[T]
           (configData:Elem, clazz:Class[T], startNode:String): Set[T] = {
    val jmsObjects = for (node &lt;- (configData \\ startNode))
      yield ( clazz.getConstructors.apply(0).newInstance(
                             (node \ &quot;@name&quot;).text
                           , (node \ &quot;jndi-name&quot;).text).asInstanceOf[T])
    jmsObjects.toSet
  }
</pre>
<p>Which you can then call like this:</p>
<pre class="brush: scala; title: ; notranslate">
buildListOfJmsObjectsFromConfigData (configData, classOf[JmsConnectionFactory]
           , &quot;connection-factory&quot;)
</pre>
<p>This looked quite Java-ish to me, as well as complex and obfuscated. </p>
<p>Our second attempt removes the loop and uses currying. It looks like  this:</p>
<pre class="brush: scala; title: ; notranslate">
def buildListOfJmsObjectsFromConfigData[T]
            (configData:Elem, startNode:String) (f:(NodeSeq) =&gt; T): Set[T] = {
     (configData \\ startNode).map(f).toSet
}
</pre>
<p>This second variant of buildListOfJmsObjectsFromConfigData[T] can be called like this:</p>
<pre class="brush: scala; title: ; notranslate">
      buildListOfJmsObjectsFromConfigData (configData, &quot;topic&quot;) {
        node =&gt; new JmsTopic((node \ &quot;@name&quot;).text, (node \ &quot;jndi-name&quot;).text)
      }
</pre>
<p>This works because the (configData \\ startNode) yields a set of objects on which we call map. Map takes a function as a parameter. The function shown above extracts a JmsTopic object, so we end up with a collection of JmsTopic instances. </p>
<p>I&#8217;m happy with our final version. It is concise and clear as well as extensible; way better than my first Java-ish version. </p>
<p><a href='http://blog.xebia.com/2011/04/03/getting-the-java-out-of-your-scala/java2scalablog/' rel='attachment wp-att-6624'>The code is attached here. </a><br />
I created three versions that are exercised in a unit test. JmsConfigReaderV1 is the first Java-ish version, JmsConfigReaderV2 is the compact but obfuscated solution and JmsConfigReaderV3 is my final attempt.<br />
I&#8217;m sure there are lots of opportunities to improve, so I welcome your opinions ans comments.</p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="small" count="1" href="http://blog.xebia.com/2011/04/03/getting-the-java-out-of-your-scala/"></g:plusone></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.xebia.com%2F2011%2F04%2F03%2Fgetting-the-java-out-of-your-scala%2F&amp;title=Getting%20the%20Java%20out%20of%20your%20Scala" id="wpa2a_6"><img src="http://blog.xebia.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.xebia.com/2011/04/03/getting-the-java-out-of-your-scala/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Saved by Fitnesse</title>
		<link>http://blog.xebia.com/2011/02/08/saved-by-fitnesse/</link>
		<comments>http://blog.xebia.com/2011/02/08/saved-by-fitnesse/#comments</comments>
		<pubDate>Tue, 08 Feb 2011 19:41:28 +0000</pubDate>
		<dc:creator>Jan Vermeir</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Tools]]></category>

	<!-- AutoMeta Start -->
	<category>fitnesse</category>
	<category>regrouping</category>
	<category>factoring</category>
	<category>green</category>
	<category>refactoring</category>
	<category>laughter</category>
	<category>shuffling</category>
	<category>confident</category>
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://blog.xebia.com/?p=5875</guid>
		<description><![CDATA[We&#8217;ve been busy for a couple of weeks now refactoring a fairly complex code base of just under 500 classes. None of us really knew all the details about this part of the system, but we didn&#8217;t let that stop us of course. After some regrouping/-shuffling/-factoring/*ing, the whole thing built OK and all unit tests [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve been busy for a couple of weeks now refactoring a fairly complex code base of just under 500 classes. None of us really knew all the details about this part of the system, but we didn&#8217;t let that stop us of course. After some regrouping/-shuffling/-factoring/*ing, the whole thing built OK and all unit tests were green again. All that was left to do was fix the Fitnesse tests. I remember thinking this should be easy since we had all those green unit test. </p>
<p>Evil laughter sounds.<br />
<span id="more-5875"></span><br />
We rely heavily on <a href="http://fitnesse.org/">Fitnesse</a> because it allows us to write specifications for our code in a way that is executable as well as understandable for others. You can even finish test cases before the coding is done so the tests work as part of the definition of done for a user story during a Sprint. The tests helped us to understand what the code was supposed to do, on a much higher level of abstraction than a unit test. This made it easier to find out what should be happening and fix the errors that were introduced by our refactoring. Because the Fitnesse tests make about 20,000 assertions we&#8217;re pretty confident the code still does what it did before. </p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="small" count="1" href="http://blog.xebia.com/2011/02/08/saved-by-fitnesse/"></g:plusone></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.xebia.com%2F2011%2F02%2F08%2Fsaved-by-fitnesse%2F&amp;title=Saved%20by%20Fitnesse" id="wpa2a_8"><img src="http://blog.xebia.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.xebia.com/2011/02/08/saved-by-fitnesse/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Bare bones SOA</title>
		<link>http://blog.xebia.com/2010/11/16/bare-bones-soa/</link>
		<comments>http://blog.xebia.com/2010/11/16/bare-bones-soa/#comments</comments>
		<pubDate>Tue, 16 Nov 2010 06:00:11 +0000</pubDate>
		<dc:creator>Jan Vermeir</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[SOA]]></category>

	<!-- AutoMeta Start -->
	<category></category>
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://blog.xebia.com/?p=872</guid>
		<description><![CDATA[Software vendors have hijacked a potentially useful concept by pushing heavy weight complex tools like ESBs. The goal of this article is to find out which of those tools we really need so we can stay away from unnecessary complexity. I&#8217;ll do that by describing the infrastructure services we really need and how these services [...]]]></description>
			<content:encoded><![CDATA[<p>Software vendors have hijacked a potentially useful concept by pushing heavy weight complex tools like ESBs. The goal of this article is to find out which of those tools we really need so we can stay away from unnecessary complexity. I&#8217;ll do that by describing the infrastructure services we really need and how these services can be implemented in the simplest possible way.</p>
<p>Software depends on other software because we don&#8217;t want to build systems from scratch. Each piece of software your code depends on may:<br />
- change the address or name by which it is known<br />
- change the technology it is implemented in<br />
- be unavailable when you need it<br />
- live on a different server or in the same process<br />
- be connected through infrastructure that cannot be trusted<br />
- speak a different language<br />
<span id="more-872"></span><br />
<strong>Names</strong><br />
A name is no more than an abstraction: using an algorithm a name can be translated into something useful.<br />
In networks we&#8217;re already used to names: nobody types IP addresses to locate a server on the Internet, we just use an easy to remember name. The mapping of this name to a physical address may change over time, but the rate of this change tends to be much slower than the rate of change for the software that is represented by the name.<br />
Basically, we can get away with a DNS-like registry to translate service names into information that allows software to call a method on a server.<br />
A message broker could be useful, but if all we need is an extended naming service we might as well use a directory. Plumbing software, the code that is used by our business code to call a service, performs a lookup of a service and stores the result. This avoids costly round trips to a broker. Compare this to the way a browser uses a DNS: the name is translated to an IP address and the result is cached until an error occurs. When an error occurs the lookup is executed again and the new result is used until further notice.<br />
This solution is easy, robust, avoids a single point of failure for most calls, allows change etc.<br />
Most software changes location over time, but changes occur at a slow rate. Messages shouldn&#8217;t be forced to pass through expensive infrastructure each and every time.</p>
<p>As an example, lets consider the interaction between two applications:<br />
App1 sends a message to a broker via a firewall<br />
The broker sends a message to App2 via a firewall<br />
App2 returns results to App1, using broker and firewall</p>
<p>By the way, App1 and App2 are deployed as two EARs in a single Weblogic instance. This simple form of interaction should not be implemented by the complex process outlined above.</p>
<p><strong>Managing unavailability</strong><br />
Most processes require an answer right here and now, but unfortunately some systems are unavailable during several hours a day. You can accept data and promise to handle the request later. To do this safely you can either store data in a database or put a message on a queue.<br />
Queues are an important piece of middleware that is well understood, widely available on many different platforms (most notably mainframes) and can be configured to never loose a message and be always available.<br />
Therefore I consider queues an essential part of any non-trivial infrastructure.</p>
<p><strong>Security</strong><br />
The basic concepts of security are identity and confidentiality. Within a company infrastructure both are addressed by plain SSL connections. There&#8217;s more to security, but we&#8217;ll save that for later. My rule is that simple problems require simple solutions, so I&#8217;m claiming that SSL will do most of the time.</p>
<p><strong>XML</strong><br />
Angle brackets are performance hogs. XML is inefficient in network bandwidth use and requires costly marshalling and unmarshalling. It may be easy to use for developers, but the cost of infrastructure in terms of servers and networks may easily outweigh the benefits of development efficiency.<br />
I&#8217;ll even go one step further: XML was never intended to be used at runtime. Using concepts like XMLSchema we have a powerful, machine readable way to define messages. But does this imply we need all that dead weight between angle brackets all of the time? Again, following the simplicity rule I would rather choose a message format that can be parsed and transported efficiently. Like in the security case there is more to say on this topic later.</p>
<p><strong>Batch processing</strong><br />
Batch processing differs from OLTP. Batches are about hundredths or thousandths of messages each hour or day. If you handle each message as a unique item, looking up the location of the service that should handle it, translate contents to XML, send it to a broker over a network, translate to Esperanto, send to another server over a network, translate to more XML, then call a service, then send the result back the other way around, batches will take down your infrastructure when volume starts to grow.<br />
You may come away with this for OLTP but it will fail miserably for large numbers of messages.<br />
So treat batches with the respect they deserve and design a solution that balances runtime performance and design time efficiency.</p>
<p><strong>The list so far</strong><br />
What we need in infrastructure so far is the list of concepts and tools below:<br />
- a directory that allows software to find other software, even if the target moves<br />
- a mechanism to postpone processing to a later point in time<br />
- a solution to ensure confidentiality and identity<br />
- an efficient message format<br />
- a batch processing strategy that can cope with large numbers of messages</p>
<p><strong>Life isn&#8217;t always easy</strong><br />
You may end up composing a service out of smaller services to offer easy access or capture knowledge about how to use services.<br />
Services may not speak the same language.<br />
Sometimes you are forced to encrypt a portion of a message because it is send as part of a larger message that shouldn&#8217;t be readable while it passes through infrastructure.</p>
<p>The items above are valid concerns that become important at the fringes of your company or department infrastructure:<br />
Composing services into a larger service stores knowledge and is therefore a useful concept. It also improves efficiency if the services are called over a slow network.</p>
<p>It is useful to standardize on a common dialect to be used throughout the enterprise. If you cannot start from scratch you will need something to translate between dialects. Also, standards are fine for exchanging data with business partners, but they may be to cumbersome to use in the enterprise. So we need something to translate at the borders. Maybe there&#8217;s a standard XML format for the exchange of messages in an industry.</p>
<p>In business-to-business message exchange we can imagine a broker service that forwards messages based on characteristics in a header section. The body of the message may be highly confidential, so it should be encrypted. This is where SSL falls short and we need something more sophisticated.</p>
<p><strong>Conclusion</strong><br />
In this article I argued that within an enterprise we rarely need brokers and can get by using simple measures like directories and SSL connections. If the enterprise grows or you start exchanging information with business partners, you may need more sophisticated infrastructure. So, brokers, XML and the full plethora of WS* standards fit nicely in your DMZ but are overkill elsewhere.</p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="small" count="1" href="http://blog.xebia.com/2010/11/16/bare-bones-soa/"></g:plusone></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.xebia.com%2F2010%2F11%2F16%2Fbare-bones-soa%2F&amp;title=Bare%20bones%20SOA" id="wpa2a_10"><img src="http://blog.xebia.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.xebia.com/2010/11/16/bare-bones-soa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Write code or step aside</title>
		<link>http://blog.xebia.com/2010/10/07/write-code-or-step-aside/</link>
		<comments>http://blog.xebia.com/2010/10/07/write-code-or-step-aside/#comments</comments>
		<pubDate>Thu, 07 Oct 2010 17:44:34 +0000</pubDate>
		<dc:creator>Jan Vermeir</dc:creator>
		<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/blog.xebia.com/www/wp-content/plugins/autometa/autometa.php</b> on line <b>303</b><br />
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[General]]></category>

	<!-- AutoMeta Start -->
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://blog.xebia.com/?p=5397</guid>
		<description><![CDATA[Most IT careers start with a programming job: you write code in one of the popular programming languages as part of a team. As your experience grows you start to get bored with software: you&#8217;ve been working with more or less the same technology and tool set for a couple of years and you need [...]]]></description>
			<content:encoded><![CDATA[<p>Most IT careers start with a programming job: you write code in one of the popular programming languages as part of a team. As your experience grows you start to get bored with software: you&#8217;ve been working with more or less the same technology and tool set for a couple of years and you need something new to keep yourself going. That&#8217;s the point where you have several options like becoming a project manager, coach, analyst or middleware expert. This story is about another option: becoming an architect.<br />
<span id="more-5397"></span><br />
At first, being an architect is relatively easy. Using the skills you gained while becoming a successful developer you can easily help others in a team of developers to be successful as well. You know what works and what doesn&#8217;t because you&#8217;ve solved similar problems on a similar platform. Because you&#8217;re more experienced you can be the natural leader of the team, the interface to the business owner and other stakeholders. Managing the teams’ environment becomes your job because you can explain complex technology and team dynamics to non-technical people. You coast along and leave the drudgery of coding to other people. </p>
<p>Excellent. </p>
<p>Time goes by and you get involved in projects you didn&#8217;t write any code for. You look at the technology stack used and you realize they&#8217;re using this new fangled TechnologyX. You read the tutorial on the Internet and you think &#8216;OK, I understand, TechnologyX solves ProblemY, great&#8217;. Next time a customer asks you for a solution to ProblemY you tell them the story of this other project where they used TechnologyX. You&#8217;re no expert yourself, but you&#8217;ve got a colleague who knows all about it. Next problem, please!<br />
In the mean time, in a parallel universe you know nothing about, people start using other technology that also solves ProblemY in radically different ways but since you didn&#8217;t stumble on these things you just don&#8217;t know. You&#8217;ve lost the ability to learn something radically new. You are stuck. Your waistline grows and you have become waste.</p>
<p>I strongly believe there is only one way to grow your professional skills and to keep increasing your value for your customers. You have to continue learning new technology. Not just by reading about it but by experiencing new technology and new techniques first hand.<br />
The process goes like this:</p>
<ol>
<li>Watch the presentation on InfoQ so you can sift out the obviously useless stuff.
</li>
<li>Read more on technology that passes the filter above so you know to what kind of problems it might be applied.
</li>
<li>Download the code for technology that might be useful for the problem you are working on or expect to be working on in the near future.
</li>
<li>Use the new stuff to solve a problem you&#8217;ve solved before so you can focus on the technology instead of the business problem at hand (if you feel really un-inspired you can just build yet another PetStore).
</li>
<li>Apply the new technology to a real life problem in a real project with real developers and a real deadline.
</li>
<li>
Repeat from step 1.
</li>
</ol>
<p>The crucial step in the list above is step 5: without real-life experience and especially without a deadline you will never find out if it works. In particular, you will never find out where technology hurts and where it facilitates. Architecture happens in development teams. </p>
<p>This only leaves one final step: share your knowledge with your peers in other projects so your organization learns. And never ever forget step 5.</p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="small" count="1" href="http://blog.xebia.com/2010/10/07/write-code-or-step-aside/"></g:plusone></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.xebia.com%2F2010%2F10%2F07%2Fwrite-code-or-step-aside%2F&amp;title=Write%20code%20or%20step%20aside" id="wpa2a_12"><img src="http://blog.xebia.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.xebia.com/2010/10/07/write-code-or-step-aside/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Life Beyond Distributed Transactions</title>
		<link>http://blog.xebia.com/2010/07/22/life-beyond-distributed-transactions/</link>
		<comments>http://blog.xebia.com/2010/07/22/life-beyond-distributed-transactions/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 15:48:44 +0000</pubDate>
		<dc:creator>Jan Vermeir</dc:creator>
				<category><![CDATA[NoSQL]]></category>

	<!-- AutoMeta Start -->
	<category></category>
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://blog.xebia.com/?p=5036</guid>
		<description><![CDATA[In an attempt to better understand the ideas behind &#8216;Life Beyond Distributed Transactions, an Apostate&#8217;s Opion.&#8217; by Pat Helland, I&#8217;m going to try to explain how the concept would work out for a time-honored example: the good old transfer of money from one account to the other, the archetype of all distributed transactions because we [...]]]></description>
			<content:encoded><![CDATA[<p>In an attempt to better understand the ideas behind <a href="http://nosqlsummer.org/paper/life-beyond-distributed-transactions">&#8216;Life Beyond Distributed Transactions, an Apostate&#8217;s Opion.&#8217; by Pat Helland</a>, I&#8217;m going to try to explain how the concept would work out for a time-honored example: the good old transfer of money from one account to the other, the archetype of all distributed transactions because we want to make absolutely sure we don&#8217;t lose money.<br />
<span id="more-5036"></span><br />
I always took for granted that you really need a distributed transaction to solve the money transfer problem: money disappears at one end of the deal and shows up at the other. Executing only one of the two actions leaves someone with a problem. So you need a transaction to safe guard the operation, moreover you need a distributed transaction because the accounts may be owned by different banking systems. That&#8217;s the point where reality sneaks up from behind your back and hits you over the head: there never is going to be such a thing as a transaction that spans two banks. At least, not in the sense that a debit action by Bank A is only visible until the corresponding credit action by Bank B is completed successfully. It would simply take too much time to complete anything at all because it may take (quite literally) days for the money to travel from A to B. All this time every read operation of the balance at Bank A would show the amount before deduction.<br />
Working with distributed transactions across two banking systems would create a brittle system where the application or infrastructure would have to remember a possibly large set of operations that haven&#8217;t yet completed and may be rolled back at any point in time. So that&#8217;s not how it works, there are no distributed transactions between banks. </p>
<p>Given the ideas in &#8216;Life..&#8217; we can solve the transfer problem in a generic way that works for transfers between banks and it also works for transfers between accounts stored in the same database, because the problem is far less complex. Applying the concepts described below even if there is only a single banking system involved, makes sense because it allows you to scale the application beyond the boundaries of a single server. </p>
<p>The first thing we need is an entity. In therms of &#8216;Life&#8230;&#8217; an entity is a set of data that is persisted as a unit. This might be my checking account at Bank A with all the transactions against it or the data the bank needs to store about me as a customer. Note that I wrote &#8216;my checking account&#8217; and &#8216;me as a customer&#8217;. The &#8216;my&#8217; and &#8216;me&#8217; are important because in this context the term entity is used to mean a specific collection of data. In the traditional sense of entity relationship diagrams an entity would be the prototype to create many instances of database records, rather like a class is used to create many objects. Pat Helland redefines the term entity to mean &#8216;a specific instance&#8217;. In size an entity would be larger than an object. Account entities would probably contain many objects, like all transactions against the account for the last two years.<br />
Now for the money transfer. In a traditional non distributed application something like this would happen: lock account A; lock account B; after checking the balance and making sure the deduction is OK, deduct amount from A; add amount to B; write to store; commit. Even though the accounts are stored in a single database, this would be classified as a distributed transaction in the sense of the article because it spans the entities account A and account B.<br />
To solve the problem you might buy a humongous IBM beast of a server, but you could also reconsider your software architecture and come up with a solution like the one below (and then you could still buy a humongous IBM server, that doesn&#8217;t really matter). </p>
<p>The solution relies on three concepts: entities, messages and activities. We&#8217;ve seen entities above, so next in line are messages. Once we&#8217;ve deducted an amount from account A, the entity associated with A has to inform the entity that manages account B that it should add the amount to account B. This is done with a message that is handed to the infrastructure. Entities have two layers: a business layer that is blissfully unaware of technology (it is scale agnostic) and an infrastructure layer that is scale aware. The infrastructure layer sends a message to entity B. It starts trying to deliver the message once it is received from entity A. The scale aware layer of entity A may have to hunt down entity B in order to deliver the message. It may fail for technical reasons (entity B is not reachable due to a network failure) or business reasons (the account in entity B is not valid).<br />
The code in entity A must deal with failure in the future: failure may occur some time after the message is sent. This is where the third concept, Activities, come into play. An activity is data about the conversation entity A has with entity B. Once entity A has placed the message on its out-queue, the activity will store this fact. If a success message is received from entity B, the activity is closed. If on the other hand a failure occurred, entity A has all the information it needs to act. A possible action could be to add the amount back to the account and send an email to the customer or log a failure message to the in-box of a bank employee. These actions may require the cooperation of other entities and thus lead to new messages and new activities, each working in its own transactional scope.</p>
<p>To summarize we saw that Entities are a collection of instances of data or objects that make some business sense. An entity has a scale agnostic and a scale aware layer. The scale aware layer deals with the delivery of messages to other entities. The scale agnostic layer stores information on messages sent to another entity in order to handle failures that cannot be automatically resolved by the scale aware layer. A transaction ends with the creation of a message. Interaction with other entities is never part of a transaction because other entities may live on a different server that might be unavailable. Activities store information on the exchange of messages between two entities and can be used by the scale agnostic business layer to handle failure.  </p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="small" count="1" href="http://blog.xebia.com/2010/07/22/life-beyond-distributed-transactions/"></g:plusone></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.xebia.com%2F2010%2F07%2F22%2Flife-beyond-distributed-transactions%2F&amp;title=Life%20Beyond%20Distributed%20Transactions" id="wpa2a_14"><img src="http://blog.xebia.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.xebia.com/2010/07/22/life-beyond-distributed-transactions/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Complexity as an early indicator for trouble</title>
		<link>http://blog.xebia.com/2010/04/27/complexity-as-an-early-indicator-for-trouble/</link>
		<comments>http://blog.xebia.com/2010/04/27/complexity-as-an-early-indicator-for-trouble/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 12:11:40 +0000</pubDate>
		<dc:creator>Jan Vermeir</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Audits]]></category>

	<!-- AutoMeta Start -->
	<category></category>
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://blog.xebia.com/?p=4489</guid>
		<description><![CDATA[Knowledge of the past allows us to predict the future, at least, for certain areas of human enterprise. I&#8217;m convinced that software development is one such area. The theme of this blog is &#8216;to measure = to know and to know = to predict&#8217;, so by the transitivity of equals we can state &#8216;to measure [...]]]></description>
			<content:encoded><![CDATA[<p>Knowledge of the past allows us to predict the future, at least, for certain areas of human enterprise. I&#8217;m convinced that software development is one such area. The theme of this blog is &#8216;to measure = to know and to know = to predict&#8217;, so by the transitivity of equals we can state &#8216;to measure = to predict&#8217;.<br />
But what should we measure? I suggest you at least measure the following and will try to explain why below: trends in burn down, trends in bugs, trends in test coverage and trends in complexity.</p>
<p><span id="more-4489"></span></p>
<p><strong>Trends in burn down</strong> is a measurement of the number of story points implemented in an iteration (if you don&#8217;t use story points you can try some other measure like use cases or pages in a requirements document or whatever as long as you can measure for a significant period and the measured entity remains constant over time). If a team works on a system for some time the number of story points in each release will tend to stabilize. This is because the team learns about the subject matter of the system, learns each others capabilities and learns how to translate user stories into technology. So if you plot the number of story points per iteration against time you should find a horizontal line. If the number of story points per iteration goes down, there&#8217;s something wrong and you should investigate the cause. More on this below as we discuss complexity.</p>
<p><strong>Trends in bugs</strong> is the number of open bugs in Jira or Bugzilla. If the development team implements story points and fixes bugs and the test team tests user stories, the number of bugs found should cancel out the number of bugs fixed. If the number of open bugs goes up this may be because testers test better (or more) and therefore find more bugs. This is actually a good thing (since the point of testing is to find bugs), though it means the team has more work to do. If the test effort remains the same and the number of bugs still goes up and the velocity is constant, the team is producing more bugs and we have a potential problem. Again, more on this below.</p>
<p><strong>Trends in test coverage</strong>. The coverage of unit tests should be high (80% or better is our rule of thumb) and remain high during the project. If test coverage drops this may just be sloppiness: nobody cares any more and writing tests is considered to be extra work so it is easy to stop writing tests. This means the team is taking a risk that may lead to more Jira issues later on. But again, there may be another cause, see below.</p>
<p><strong>Trends in complexity</strong> is about the average complexity of methods in the system. A generally accepted measurement of complexity is McCabe&#8217;s cyclomatic complexity. The actual measure used doesn&#8217;t really matter as long as it remains the same during the project. I propose to use the complexity of classes as a measure. </p>
<p>If a project is about to derail we want to know as early as possible. My statement is that complexity is the measurement to track:</p>
<ol>
<li>If complexity goes up it will become harder to implement new features. This leads to lower velocity but not immediately. After a while velocity will go down because it takes longer to implement new features.</li>
<li>
Complex code will also show more bugs so the ratio of new bugs versus fixed bugs will go up. Again this will take a while, especially if testing is done by a separate test team on a release, instead of by a tester who is part of the team.</li>
<li>
Writing unit tests for complex code is harder so if you are struggling to get the story implemented because the code base is hard to understand, writing a unit test may be the first activity that gets dropped. At first test coverage will remain the same, but as it gets harder to write tests because complexity is going up, coverage will start to go down.</li>
</ol>
<p>So, the measurement to watch is complexity as it develops in time. An excellent way to do this is to install Sonar (http://www.sonarsource.org/) and add it to the Maven build on your build server.<br />
The other measures (burn down, bugs and test coverage) are interesting in their own right and serve as supporting evidence, so I suggest to measure them and plot them against time as well. </p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="small" count="1" href="http://blog.xebia.com/2010/04/27/complexity-as-an-early-indicator-for-trouble/"></g:plusone></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.xebia.com%2F2010%2F04%2F27%2Fcomplexity-as-an-early-indicator-for-trouble%2F&amp;title=Complexity%20as%20an%20early%20indicator%20for%20trouble" id="wpa2a_16"><img src="http://blog.xebia.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.xebia.com/2010/04/27/complexity-as-an-early-indicator-for-trouble/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prima Donna Syndrome</title>
		<link>http://blog.xebia.com/2010/04/27/prima-donna-syndrome/</link>
		<comments>http://blog.xebia.com/2010/04/27/prima-donna-syndrome/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 07:52:21 +0000</pubDate>
		<dc:creator>Jan Vermeir</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Project Management]]></category>

	<!-- AutoMeta Start -->
	<category></category>
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://blog.xebia.com/?p=4482</guid>
		<description><![CDATA[Development teams or even development organizations, are not always the well balanced, smooth operations we&#8217;d like them to be. In our software quality audit practice we have had the privilege to investigate many different types of organizations and found many different ways quality and productivity can suffer from a problem known as the Prima Donna [...]]]></description>
			<content:encoded><![CDATA[<p>Development teams or even development organizations, are not always the well balanced, smooth operations we&#8217;d like them to be. In our software quality audit practice we have had the privilege to investigate many different types of organizations and found many different ways quality and productivity can suffer from a problem known as the Prima Donna Syndrome: a single individual exercises a disproportionate influence on the team causing problems like stagnation and unnecessary complexity.<br />
<span id="more-4482"></span></p>
<p>A Prima Donna is known outside of the software development world as the star of the opera, the one singer who can turn a nice evening out into an unforgettable experience. Sure, other vocalists and dancers are important, but their influence on the overall result is negligible. If the star of the show has an off-day, it doesn&#8217;t matter how well the rest of the cast performs; if on the other hand the star of the show is at his or her best, the audience will reward the cast with a standing ovation. Of course, the Prima Donna starts using this status to make demands that may gradually become absurd. </p>
<p>A software development team can suffer from a similar affliction. If one of the developers on the team is much more experienced than his team mates, it is only natural that this person has control over most of the important decisions. He may feel he is the only person on the team capable of setting directions, choosing architecture, modularization, selecting libraries, tools and build infrastructure. Others follow or leave and gradually the imbalance in the team grows. Because the Prima Donna knows best, he will get an important vote in hiring new team members. To defend his position he will favor docile people who are more easily controlled, and the team suffers even more.<br />
The effects on software architecture can be devastating. The Prima Donna doesn&#8217;t need understandable code. On a small scale this isn&#8217;t so much of a problem, but in a large software project you may end up with unmaintainable spaghetti. Other team members may be unwilling or incapable to make changes to code developed by someone else for fear of breaking something or just because they can&#8217;t get their heads around it. Lack of shared ownership of a code base leads to duplication, dead code, more code and more duplication and so on. New developers face a steep learning curve, taking years to become productive. </p>
<p>So how do we get rid of this imbalance? </p>
<p>The first part of the solution is to spread responsibility among groups of team members by setting up feature teams. The main idea is to set up teams that will implement a small part of the system. Each team has representatives from all disciplines necessary to finish the job: designers, business logic experts, DBA&#8217;s and service developers are all part of a small team that will implement a feature in all its aspects. Besides allowing you to deploy small features quickly, the consequences are that people are part of a small focused team that will learn to make its own decisions. The team will have more body and will be better equipped to work with the Prima Donna, who gets a new job: keep an eye on the overall consistency of the work done by the feature teams and make sure all features work together well, make sure the architecture remains sound.<br />
A second job for the Prima Donna is trouble shooting: if there are hard to diagnose problems in production it takes in depth knowledge of the system and the platform to find a solution, often under time pressure. This kind of work is the sweet spot of a real Prima Donna&#8217;s skills. </p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="small" count="1" href="http://blog.xebia.com/2010/04/27/prima-donna-syndrome/"></g:plusone></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.xebia.com%2F2010%2F04%2F27%2Fprima-donna-syndrome%2F&amp;title=Prima%20Donna%20Syndrome" id="wpa2a_18"><img src="http://blog.xebia.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.xebia.com/2010/04/27/prima-donna-syndrome/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Parsing Text with Scala</title>
		<link>http://blog.xebia.com/2009/10/21/parsing-text-with-scala/</link>
		<comments>http://blog.xebia.com/2009/10/21/parsing-text-with-scala/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 16:15:50 +0000</pubDate>
		<dc:creator>Jan Vermeir</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Scala]]></category>

	<!-- AutoMeta Start -->
	<category></category>
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://blog.xebia.com/?p=3259</guid>
		<description><![CDATA[In my efforts to teach myself Scala, I tried solving a problem I&#8217;ve tackled in various languages, 6510 assembly code (didn&#8217;t get far&#8230;), pl/sql, Java (with and without Drools) and Groovy among them. Usually I get bogged down in some detail of the language so I never get to reap any actual benefits of my [...]]]></description>
			<content:encoded><![CDATA[<p>In my efforts to teach myself Scala, I tried solving a problem I&#8217;ve tackled in various languages, 6510 assembly code (didn&#8217;t get far&#8230;), pl/sql, Java (with and without Drools) and Groovy among them. Usually I get bogged down in some detail of the language so I never get to reap any actual benefits of my efforts in daily life. The plus side of this never ending task is that by now I don&#8217;t have to spend effort on defining a problem but instead can start coding right away.<br />
So this story is about how to parse text in Scala and is part of THE software package that will automagically generate a menu for a week and the shopping list for that menu together with whatever else my family will need that week and send it to www.albert.nl and have the groceries delivered to my door.<br />
<span id="more-3259"></span><br />
Thinking big and starting small, I set about (again) parsing a set of recipes so I can extract the list of ingredients necessary for the shopping list. Since all of my practical knowledge of Scala came from reading the book by Martin Odersky, there was some evolution in my code. As we go, I&#8217;ll try and amuse you with some  of the clunky contraptions I&#8217;ve created along the way while trying to shake of old habits. </p>
<p>The aim is to parse a list of recipes like the one below:</p>
<pre class="brush: plain; title: ; notranslate">
name ZucchiniWithMinceMeat
season summer
category easy
cookingtime 45 minutes
preheat oven at 180 degrees
fry 500 gram mincemeat
fry 1 piece Zucchini
add 1 can mashedTomatoes
add 1 bag groundCheese
bake for 30 minutes
</pre>
<p>and turning it into a list of groceries like this:</p>
<pre class="brush: plain; title: ; notranslate">
mincemeat 500 gram
Zucchini 1 piece
mashedTomatoes 1 can
groundCheese 1 bag
</pre>
<p>Scala offers a parser for text named StandardTokenParsers in the package scala.util.parsing.combinator.syntactical. The idea is that  a specific parser extends StandardTokenParsers. The parser should provide </p>
<li>A list of delimiters
<li>A list of reserved words
<li>A &#8216;main&#8217; method that accepts text input and starts the parser
<li>A set of production rules that parse part of the input, building an object graph along the way.
<p>lexical.delimiters is the list of characters used to separate tokens in the input.<br />
lexical.reserved defines a set of key words, i.e. the while, if, for etc of your language. The snippet below shows my definitions (it is part of com.xebia.cooking.CookBookDSL.scala, which you can find in the zip file <a href="http://blog.xebia.com/wp-content/uploads/2009/10/dsl.zip">attached</a> to this post.).</p>
<pre class="brush: scala; title: ; notranslate">
  lexical.delimiters ++= List(&quot;(&quot;, &quot;)&quot;, &quot;,&quot;, &quot; &quot;, &quot;\n&quot;)
  lexical.reserved ++= List(&quot;name&quot;, &quot;season&quot;, &quot;fry&quot;, &quot;pack&quot;, &quot;can&quot;, &quot;bag&quot;, &quot;piece&quot;, &quot;at&quot;, &quot;for&quot;, &quot;bottle&quot;, &quot;gram&quot;, &quot;oven&quot;, &quot;preheat&quot;, &quot;bake&quot;, &quot;serve&quot;, &quot;with&quot;,&quot;add&quot;,&quot;degrees&quot;, &quot;category&quot;, &quot;cookingtime&quot;)
</pre>
<p>lexical is of type Lexical and is an inherited attribute of StandardTokenParsers.</p>
<p>The parser is started like this:</p>
<pre class="brush: scala; title: ; notranslate">
  def parseCookBook(cookBook:String):CookBook = {
		cookbook(new lexical.Scanner(cookBook)) match {
		  case Success(recipeList, _) =&gt; new CookBook(recipeList)
 		  case Failure(msg, _) =&gt; throw new ParseErrorException(msg)
		  case Error(msg, _) =&gt; throw new ParseErrorException(msg)
		}
  }
</pre>
<p>The input is a string representation of a cookbook. parseCookBook returns an object of type CookBook which we will discuss later. The parsing is kicked off by calling the cookbook method with an instance of a Scanner as a parameter. The Scanner will emit tokens that are matched with the rules of the grammar as we&#8217;ll see below.<br />
Using Scala&#8217;s case construct the result of the parser is translated in either a CookBook instance or results in an exception. </p>
<p>The parser consists of a set of rules in the form of method definitions that look like the one below:</p>
<pre class="brush: scala; title: ; notranslate">
  def recipeName: Parser[String] =
    &quot;name&quot; ~ ident ^^ { case &quot;name&quot; ~ name =&gt; name }
</pre>
<p>The rule defines the name of a recipe as a String. The text to the left of the ^^ operator defines the tokens that must appear in the input for the rule to match. In this case we expect the string &#8220;name&#8221; followed by an identifier. ident is defined in StdTokenParsers (along with numericLit which I&#8217;ll use later) and matches a string of alphanumeric characters. The tokens that are thus parsed are used to select a action to the right of the ^^ sign. &#8220;name&#8221; ~ name introduces a variable named name that is initialized with the value of the ident token. name is then returned as a result of the rule by placing it to the right of the => sign.</p>
<p>A slightly more complex example is shown below:</p>
<pre class="brush: scala; title: ; notranslate">
  def ingredient: Parser[Ingredient] =
	opt(amount) ~ ident ^^
  	{ case Some(amount) ~ ingredient =&gt; (new Ingredient(ingredient,amount))
  	  case  _ ~ ingredient =&gt; {new Ingredient(ingredient)}
  	}
</pre>
<p>This rule matches text like &#8220;500 gram mincemeat&#8221;, &#8220;1 piece Zucchini&#8221; but also &#8220;salad&#8221; or &#8220;tomatoes&#8221;. The amount part of the definition is made optional. Instead of just one case clause like we saw in the first rule, this rule has two cases. The first matches an amount followed by an ingredient, the second matches just an ingredient without the amount part. </p>
<p>One rule can build on the results of other rules as illustrated below:</p>
<pre class="brush: scala; title: ; notranslate">
  def step: Parser[Step] =
	(fryStep | preHeatStep | serveWithStep | addStep | bakeStep) ^^ { case step =&gt; step }
</pre>
<p>A step in a recipe is something like &#8220;preheat oven at 180 degrees&#8221; or &#8220;fry 500 gram mincemeat&#8221;. The clauses to the left are alternatives that are defined as separate rules. The result is always a Step instance. Steps are important because some of them define ingredients which, in some hypothetical future version of my magnum opus, will result in a shopping list (do I hear laughter?). </p>
<p>One last sample rule shows repeating elements:</p>
<pre class="brush: scala; title: ; notranslate">
  def listOfSeasons: Parser[List[Seasons]] =
    repsep(season ,&quot;,&quot;) ^^ { listOfSeasons: List[Seasons] =&gt; listOfSeasons }
}
</pre>
<p>This rule matches one or more occurrences of a season separated by a comma using the repsep clause. The result is a List of objects of type Seasons.</p>
<p>The parser code uses classes that represent concepts in my domain, like Ingredient, Step and Recipe. I&#8217;ve defined these classes in a separate source file named Recipe.scala. Most of the classes are empty and just serve to define concepts. They may become more interesting later (you know, when I implement this wonderful&#8230;, etc, etc&#8230;). Others, like StepWithAnIngredient serve to collect ingredients that will be used to create a shopping list.<br />
Anyway, one thing I learned from writing the classes in the Recipe.scala file is the use the mkString method. Given my Java background I wrote toString methods like this:</p>
<pre class="brush: scala; title: ; notranslate">
  override def toString = {
  	val result:StringBuilder = new StringBuilder(&quot;Steps: &quot;) 

   	list.foreach(step =&gt; result.append(step).append(&quot;\n&quot;))
  	result.toString()
  }
</pre>
<p>I was feeling pretty happy about this (you know, remembering to use the foreach method) until I realized this kind of thing is way easier implemented like this:</p>
<pre class="brush: scala; title: ; notranslate">
	override def toString = &quot;Steps: &quot; + steps.mkString(&quot;\n&quot;)
</pre>
<p>You can call mkString on any instance you like and it will return a string representation, which is especially convenient in the case of iterable objects.</p>
<p>Another powerful Scala feature is the set of methods defined on lists. One such method is filter that accepts a closure executed on each element of the list. If the condition returns true the element is added to the result.<br />
In the example below, the _ represents a recipe, i.e. an element of the list of recipes. </p>
<pre class="brush: scala; title: ; notranslate">
  def findRecipesBySeason(season:Seasons):Seq[Recipe] = {
    recipes.filter(_.seasons.contains(season))
  }
</pre>
<p>Another thing that had me thoroughly confused at first was the syntax for constructor parameters. The example below shows the variables amount and unitName defined in the Amount class, the Java way:</p>
<pre class="brush: java; title: ; notranslate">
public class Amount {
	private int amount;
	private String unitName;
	public Amount(int amount, String unitName) {
		this.amount=amount;
		this.unitName=unitName;
	}
	// getters and setters omitted for brevity...
}
</pre>
<p>And in Scala:</p>
<pre class="brush: scala; title: ; notranslate">
class Amount (val amount:Int, val unitName:String) {
	override def toString = amount+&quot;:&quot;+unitName
}
</pre>
<p>The parameters following the name of the class are turned into public val&#8217;s. With my Java background and my compulsion to hit ctrl-1 in Eclipse, it took me awhile to realize how easy and concise the Scala syntax is. </p>
<p>Note that the Recipe.scala file contains a list of class definitions. In Scala there is no one-to-one mapping from public classes to source files. This allowed me to combine a list of related concepts in a single source file. </p>
<p>Finally, I found that the best way to develop parsers is by taking very small steps at a time. It is pretty easy to mess things up beyond repair by changing too much at at once. </p>
<p>This Scala parser is by far the most complete version I&#8217;ve built so far. I&#8217;m now starting to like the language, even though my lack of experience gets in the way at least 15 times an hour. Who knows, I might actually create something useful this time&#8230;</p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="small" count="1" href="http://blog.xebia.com/2009/10/21/parsing-text-with-scala/"></g:plusone></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.xebia.com%2F2009%2F10%2F21%2Fparsing-text-with-scala%2F&amp;title=Parsing%20Text%20with%20Scala" id="wpa2a_20"><img src="http://blog.xebia.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.xebia.com/2009/10/21/parsing-text-with-scala/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  blog.xebia.com/author/jvermeir/feed/ ) in 1.09138 seconds, on Feb 9th, 2012 at 4:16 pm UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 9th, 2012 at 5:16 pm UTC -->
