<?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>Tomas Malmsten . com</title>
	<atom:link href="http://www.tomasmalmsten.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tomasmalmsten.com</link>
	<description>Just my tuppence worth</description>
	<lastBuildDate>Mon, 07 May 2012 06:47:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Mapping java.util.Map to XML using JAXB</title>
		<link>http://www.tomasmalmsten.com/2012/05/unmarshall-marshall-java-maps-xml-jaxb/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.tomasmalmsten.com/2012/05/unmarshall-marshall-java-maps-xml-jaxb/#comments</comments>
		<pubDate>Mon, 07 May 2012 06:47:56 +0000</pubDate>
		<dc:creator>Tomas Malmsten</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[jaxb]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.tomasmalmsten.com/?p=819</guid>
		<description><![CDATA[<p>One of the thing that can be a bit tricky when using JAXB is to map a java.util.Map to XML. In this example we have a provider object. The provider has a name and a map containing properties. Below is the provider XML document: And then the Provider class: JAXB sees the properties object in [...]</p>
 ]]></description>
			<content:encoded><![CDATA[<p>One of the thing that can be a bit tricky when using JAXB is to map a java.util.Map to XML. In this example we have a provider object. The provider has a name and a map containing properties.</p>
<p>Below is the provider XML document:</p><pre class="crayon-plain-tag">&lt;provider&gt;
  &lt;name&gt;Provider Name&lt;/name&gt;
  &lt;properties&gt;
    &lt;property&gt;
      &lt;name&gt;address&lt;/name&gt;
      &lt;value&gt;194.132.9.45&lt;/value&gt;
    &lt;/property&gt;
    &lt;property&gt;
      &lt;name&gt;username&lt;/name&gt;
      &lt;value&gt;testuser&lt;/username&gt;
    &lt;/property&gt;
    &lt;property&gt;
      &lt;name&gt;secret&lt;/name&gt;
      &lt;value&gt;433395868950ifkjjrif9985848rufj&lt;/value&gt;
    &lt;/property&gt;
  &lt;/properties&gt;
&lt;/provider&gt;</pre><p></p>
<p>And then the Provider class:</p><pre class="crayon-plain-tag">package com.tomasmalmsten.example.jaxb;

import java.util.Map;

public class Provider {
  private String name;
  private Map&lt;String, String&gt; properties;

  void setProperties(Map&lt;String, String&gt; properties) {
    this.properties = properties;
  }

  String name() {
    return name;
  }

  Map&lt;String, String&gt; properties() {
    return properties;
  }

  void setName(String name) {
    this.name = name;
  }
}</pre><p></p>
<p>JAXB sees the properties object in the XML document as a list of property entries. Therefore we need to transform the list into a map. To do this we need three supporting classes. The first one is the class containing the entry, or property:</p><pre class="crayon-plain-tag">package com.tomasmalmsten.example.jaxb;

import javax.xml.bind.annotation.XmlElement;

class Property {
  @XmlElement(name = &quot;name&quot;)
  private String name;

  @XmlElement(name = &quot;value&quot;)
  private String value;

  Property() {
  }

  Property(String name, String value) {
    this.name = name;
    this.value = value;
  }

  String value() {
    return value;
  }

  String name() {
    return name;
  }
}</pre><p></p>
<p>Next we need the class that contains the list of entries, or the properties:</p><pre class="crayon-plain-tag">package com.tomasmalmsten.example.jaxb;

import javax.xml.bind.annotation.XmlElement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

class Properties {
  @XmlElement(name = &quot;property&quot;)
  private List&lt;PropertyEntry&gt; entries = new ArrayList&lt;&gt;();

  List&lt;PropertyEntry&gt; entries() {
    return Collections.unmodifiableList(entries);
  }

  void addEntry(PropertyEntry entry) {
    entries.add(entry);
  }
}</pre><p></p>
<p>To transform the list into a map we need an XmlAdapter. An XmlAdapter is a class that instructs JAXB on how to marshal and unmarshal an object that does not conform to the JAXB standard. This could for example be a class without a public no args constructor, or as in our case the provider properties map:</p><pre class="crayon-plain-tag">package com.tomasmalmsten.example.jaxb;

import javax.xml.bind.annotation.adapters.XmlAdapter;
import java.util.HashMap;
import java.util.Map;

class PropertyAdapter extends XmlAdapter&lt;Properties, Map&lt;String, String&gt;&gt; {

  @Override
  public Map&lt;String, String&gt; unmarshal(Properties in) throws Exception {
    HashMap&lt;String, String&gt; hashMap = new HashMap&lt;&gt;();
    for (PropertyEntry entry : in.entries()) {
      hashMap.put(entry.name(), entry.value());
    }
    return hashMap;
  }

  @Override
  public Properties marshal(Map&lt;String, String&gt; map) throws Exception {
    Properties props = new Properties();
    for (Map.Entry&lt;String, String&gt; entry : map.entrySet()) {
      props.addEntry(new PropertyEntry(entry.getKey(), entry.getValue()));
    }
    return props;
  }

}</pre><p></p>
<p>Now what is left is to tell JAXB to use the XmlAdaptor when handling the properties field. To do this we use the @XmlJavaTypeAdapter annotation. Below is the fully annotated Provider class:</p><pre class="crayon-plain-tag">package com.tomasmalmsten.example.jaxb;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.util.Map;

@XmlRootElement(name = &quot;provider&quot;)
@XmlAccessorType(XmlAccessType.FIELD)
public class Provider {
  @XmlElement(name = &quot;name&quot;)
  private String name;
  @XmlElement(name = &quot;properties&quot;)
  @XmlJavaTypeAdapter(PropertyAdapter.class)
  private Map&lt;String, String&gt; properties;

  void setProperties(Map&lt;String, String&gt; properties) {
    this.properties = properties;
  }

  String name() {
    return name;
  }

  Map&lt;String, String&gt; properties() {
    return properties;
  }

  void setName(String name) {
    this.name = name;
  }
}</pre><p></p>
 <p><a href="http://www.tomasmalmsten.com/?flattrss_redirect&amp;id=819&amp;md5=9e2216728bc3e169d85cccf5483b2ca6" title="Flattr" target="_blank"><img src="http://www.tomasmalmsten.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.tomasmalmsten.com/2012/05/unmarshall-marshall-java-maps-xml-jaxb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=tomasmalmsten&amp;popout=1&amp;url=http%3A%2F%2Fwww.tomasmalmsten.com%2F2012%2F05%2Funmarshall-marshall-java-maps-xml-jaxb%2F&amp;language=en_GB&amp;category=software&amp;title=Mapping+java.util.Map+to+XML+using+JAXB&amp;description=One+of+the+thing+that+can+be+a+bit+tricky+when+using+JAXB+is+to+map+a+java.util.Map+to+XML.+In+this+example+we+have+a+provider+object.+The+provider...&amp;tags=Java%2Cjaxb%2Cxml%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Get Maven to work with Java 7u4 on a Mac</title>
		<link>http://www.tomasmalmsten.com/2012/05/java-7u4-maven-mac/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.tomasmalmsten.com/2012/05/java-7u4-maven-mac/#comments</comments>
		<pubDate>Wed, 02 May 2012 10:17:35 +0000</pubDate>
		<dc:creator>Tomas Malmsten</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[OS X]]></category>

		<guid isPermaLink="false">http://www.tomasmalmsten.com/?p=812</guid>
		<description><![CDATA[<p>I have finally install Java 7 on my laptop. The Java install runs just fine. Getting maven to find it however was a little tricky. To make Maven find Java 7 the JAVA_HOME variable is required again. This hasn&#8217;t been used for a while since Maven have been able to find Java anyway. But with [...]</p>
 ]]></description>
			<content:encoded><![CDATA[<p>I have finally install Java 7 on my laptop. The Java install runs just fine. Getting maven to find it however was a little tricky.</p>
<p>To make Maven find Java 7 the JAVA_HOME variable is required again. This hasn&#8217;t been used for a while since Maven have been able to find Java anyway. But with the switch to 7 Maven still uses Java 6 by default.</p>
<p>I always use .bash_profile to change my environment variables since I tend not to need them else were. It is located in the users home directory (I.E. ~/.bash_profile).</p>
<p>The path to the new Java install is &#8216;/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/&#8217;. So the complete setting should look like this: </p>
<blockquote><p>$JAVA_HOME=/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/</p></blockquote>
<p>When this has been configured Maven will use Java 7.</p>
 <p><a href="http://www.tomasmalmsten.com/?flattrss_redirect&amp;id=812&amp;md5=590c6ec3a43b0d299e5bcf801c114c1d" title="Flattr" target="_blank"><img src="http://www.tomasmalmsten.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.tomasmalmsten.com/2012/05/java-7u4-maven-mac/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=tomasmalmsten&amp;popout=1&amp;url=http%3A%2F%2Fwww.tomasmalmsten.com%2F2012%2F05%2Fjava-7u4-maven-mac%2F&amp;language=en_GB&amp;category=software&amp;title=Get+Maven+to+work+with+Java+7u4+on+a+Mac&amp;description=I+have+finally+install+Java+7+on+my+laptop.+The+Java+install+runs+just+fine.+Getting+maven+to+find+it+however+was+a+little+tricky.+To+make+Maven+find+Java...&amp;tags=Java%2Cmaven%2COS+X%2Cblog" type="text/html" />
	</item>
		<item>
		<title>I&#8217;m back&#8230;</title>
		<link>http://www.tomasmalmsten.com/2012/03/back/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.tomasmalmsten.com/2012/03/back/#comments</comments>
		<pubDate>Mon, 19 Mar 2012 12:56:18 +0000</pubDate>
		<dc:creator>Tomas Malmsten</dc:creator>
				<category><![CDATA[Life]]></category>

		<guid isPermaLink="false">http://www.tomasmalmsten.com/?p=806</guid>
		<description><![CDATA[<p>As some of you may have noticed I have not been particularly active the past three or so months. This is because I have been on a trip to India with my family. We have been traveling around in south west India for 99 days and had a marvelous time. But as the Swedish proverb [...]</p>
 ]]></description>
			<content:encoded><![CDATA[<p>As some of you may have noticed I have not been particularly active the past three or so months. This is because I have been on a trip to India with my family. We have been traveling around in south west India for 99 days and had a marvelous time. But as the Swedish proverb goes: &#8220;Away is good but Home is best&#8221;.</p>
<p>I am very happy to be back and this is in part thanks to my new position. I have left mBlox and joined of <a href="http://avegagroup.se/" target="_blank">Avega Group</a>. Avega Group is a Swedish consultancy firm with a focus on seniority and expertise. This means that I am available as an expert consultant within programming, technical team lead and architecture. Get in contact with <a href="mailto:Peter.Blomsterberg@avegagroup.se#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed">Peter Blomsterberg</a> if you are interested.</p>
<p>As I start with coding again I am sure I will find new and interesting things to write about.</p>
<p>Cheers!</p>
 <p><a href="http://www.tomasmalmsten.com/?flattrss_redirect&amp;id=806&amp;md5=51b373761175c51ab4e5fc46e79f625f" title="Flattr" target="_blank"><img src="http://www.tomasmalmsten.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.tomasmalmsten.com/2012/03/back/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=tomasmalmsten&amp;popout=1&amp;url=http%3A%2F%2Fwww.tomasmalmsten.com%2F2012%2F03%2Fback%2F&amp;language=en_GB&amp;category=software&amp;title=I%26%238217%3Bm+back%26%238230%3B&amp;description=As+some+of+you+may+have+noticed+I+have+not+been+particularly+active+the+past+three+or+so+months.+This+is+because+I+have+been+on+a+trip+to+India...&amp;tags=blog" type="text/html" />
	</item>
		<item>
		<title>Clean Code &#8211; Functions &#8211; Revisited</title>
		<link>http://www.tomasmalmsten.com/2011/11/clean-code-functions-revisited/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.tomasmalmsten.com/2011/11/clean-code-functions-revisited/#comments</comments>
		<pubDate>Fri, 18 Nov 2011 15:30:25 +0000</pubDate>
		<dc:creator>Tomas Malmsten</dc:creator>
				<category><![CDATA[Clean code]]></category>
		<category><![CDATA[clean code]]></category>
		<category><![CDATA[DRY]]></category>

		<guid isPermaLink="false">http://www.tomasmalmsten.com/?p=796</guid>
		<description><![CDATA[<p>A couple of years back I wrote an article exploring a way to apply Robert C. Martins guidelines on how to create clean functions, taken from his book Clean Code. This created quite a stir on DZone where I also published it. A comment from Steven Jeuris about a week ago on my blog made [...]</p>
 ]]></description>
			<content:encoded><![CDATA[<p>A couple of years back I wrote an <a href="http://www.tomasmalmsten.com/2009/02/clean-code-functions-html/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed" target="_blank">article</a> exploring a way to apply Robert C. Martins guidelines on how to create clean functions, taken from his book Clean Code. This created quite a stir on <a href="http://java.dzone.com/articles/clean-code-functions" target="_blank">DZone</a> where I also published it.</p>
<p>A comment from Steven Jeuris about a week ago on my blog made me want to revisit the subject again.</p>
<p>Since I wrote the original article I have leant a lot about creating clean functions that does one thing. And as I replied in to his comment I would not design the code in the original article the same way now.</p>
<p>The key to applying the guidelines in the book is pragmatism. There are a number of benefits from working as is suggested there. I will cover some of them below. But it cannot be followed religiously. It is after all software we are creating, not religion.</p>
<p>Steven Jeuris writes, in his <a href="http://whathecode.wordpress.com/2010/12/07/function-hell/" target="_blank">blog</a> on the subject, that a perfectly good way to make code in a function readable is to create blocks with comments. This to me is an anti pattern. There are few reasons to ever create blocks in a function, if they are required it generally indicates that the function is to long. Comments are almost always a bad idea. If a comment is required the block should be put within a function bearing a name that explains what the block does.</p>
<p>Steven Jeuris further writes that new small functions litters the name space of the class. I can see where he is coming from but again I have to disagree. If the name space of a class is littered by explanatory function names then it sounds like the class is to big and needs to be refactored. To me it sounds very much like it does more then one thing.</p>
<p>There is also an interesting side effect to creating smaller more atomic functions that does one thing. It is easier to find commonalities between the other, higher level, functions within the same class, or even related classes. This actually makes it easier to keep the code DRY (Don&#8217;t Repeat Yourself).</p>
<p>Another very important factor to keep in mind when working like this is what patterns the rest of the team are used to. The size of functions and the way to work with them are not a one size fits all. If a team is used to procedural code the step to <a href="http://blog.objectmentor.com/articles/2009/09/11/one-thing-extract-till-you-drop" target="_blank">extract till you drop</a> style functions will be really confusing. If, on the other hand, the team is used to atomic, do one thing only, functions it is hell to work with larger functions littered with comments and artificial blocks.</p>
<p>In any case, I know that if I would do the same exercise to day as I did when writing my original article on the subject it would look different, and the original definitely takes a good thing way to far.</p>
 <p><a href="http://www.tomasmalmsten.com/?flattrss_redirect&amp;id=796&amp;md5=09bb9778fa814b27ba7dda7456e32c89" title="Flattr" target="_blank"><img src="http://www.tomasmalmsten.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.tomasmalmsten.com/2011/11/clean-code-functions-revisited/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=tomasmalmsten&amp;popout=1&amp;url=http%3A%2F%2Fwww.tomasmalmsten.com%2F2011%2F11%2Fclean-code-functions-revisited%2F&amp;language=en_GB&amp;category=software&amp;title=Clean+Code+%26%238211%3B+Functions+%26%238211%3B+Revisited&amp;description=A+couple+of+years+back+I+wrote+an+article+exploring+a+way+to+apply+Robert+C.+Martins+guidelines+on+how+to+create+clean+functions%2C+taken+from+his+book+Clean+Code....&amp;tags=clean+code%2CDRY%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Designing a HATEOAS REST API</title>
		<link>http://www.tomasmalmsten.com/2011/11/creating-links-rest-api/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.tomasmalmsten.com/2011/11/creating-links-rest-api/#comments</comments>
		<pubDate>Thu, 17 Nov 2011 14:07:52 +0000</pubDate>
		<dc:creator>Tomas Malmsten</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://www.tomasmalmsten.com/?p=768</guid>
		<description><![CDATA[<p>I have recently finished designing a REST protocol. There are a few things that needs careful consideration when exposing a domain through such an interface. I will gather some of the conclusions here for future reference. The first thing to keep in mind is what a HTTP based REST protocol is and what it is [...]</p>
 ]]></description>
			<content:encoded><![CDATA[<p>I have recently finished designing a REST protocol. There are a few things that needs careful consideration when exposing a domain through such an interface. I will gather some of the conclusions here for future reference.</p>
<p>The first thing to keep in mind is what a HTTP based REST protocol is and what it is not. It is not a domain, it&#8217;s a protocol. It is easy to forget when modelling the domain that it&#8217;s representation is only a snapshot view onto it. The REST protocol provides this snapshot view. This makes a tiered architecture fitting, with clear boundaries between presentation, I.E the REST API, domain, and then any other technical aspects such as data storage.</p>
<p>Next thing to keep in mind is: What is REST over HTTP? It&#8217;s a way to access resources, or documents. That&#8217;s what we do when using the web. We don&#8217;t access domain objects. Remembering this helps when thinking about the interface as well. Most of the time when we create enterprise software we create abstract documents representing real life object. For example, when creating an e-commerce system that sells shoes it&#8217;s not the shoes that are transitioned through the work flow. It&#8217;s documents that represent the shoes or the whereabouts of them. With this frame of mind it&#8217;s much simpler to define the REST interface onto the domain.</p>
<p>Then there are the three levels of REST. Resources, verbs and hyper media controls. As described in <a href="http://martinfowler.com/articles/richardsonMaturityModel.html" target="_blank">this article</a>, by Martin Fowler, about the Richardson Maturity Model.</p>
<p>The first level is resources. This is where the document thinking comes in. When thinking about the domain model it is usually pretty simple to see how different states of it can map onto a document representation. This becomes a resource. It could be the result of an operation just as well as the state of an object.</p>
<p>The second level are the HTTP verbs. I used GET, PUT, POST and DELETE in my API.</p>
<p>GET will get the representation of a resource. A key aspect with get is that it can be called any number of times with the exact same result. It has not side effects.</p>
<p>POST and PUT are used to change things. POST is used when a resource is created or modified in such a manner that the resource path changes. One obvious use is when creating a new object that can later be addressed using it&#8217;s ID. This returns a response of 201, Created with a location header that points to where the new resource is located. POST is also used if a resource is changed in such a manner that it&#8217;s path changes.</p>
<p>An example is if you have a set of products that are accessed based on a category name. When the category name changes the product paths will also change. This kind of side effect requires a POST rather then a PUT. The response is either 200, if it contains a body, or 204 if it does not. In either case the location header needs to be present to point the client to the new location of the resource.</p>
<p>POST is also used for submitting data to a computation. If the API displays a currency converter I would use POST as the method with the amount, the from and the to currencies in the body. Here the response code is 200, the result in the body but it no location header is provided.</p>
<p>PUT is used to modify a resource. What is important here is that resource paths are not allowed to change as a side effect of the modification. It can expose ways to change properties on objects or replacing a whole object as long as the path does not change. Response is usually 204, but if a response body is retuned it&#8217;s 200.</p>
<p>DELETE is simply used to remove a resource. Response is almost exclusively 204 since a removed resource have little in the form of content to offer.</p>
<p>The third level is hypermedia controls also referred to as HATEOAS (Hypermedia as the Engine of Application State). Hypermedia controls are links to actions that can be performed on the document. My thinking on what links to provide is to point forward from the current state. The client will be responsible for keeping track of it&#8217;s history as well as weather that history is valid traversable. History validity is based on expire headers so don&#8217;t forget to provide them in each response.</p>
<p>When defining links I have used the following JSON syntax:</p><pre class="crayon-plain-tag">{&quot;links&quot;: [
    {&quot;GET&quot;: &quot;/uri/to/resource&quot;},
    ...
    {&quot;PUT&quot; : &quot;/uri/to/other/resource&quot;}
]}</pre><p>This exposes what actions are available on the current resource in an easy manner, using the HTTP verb/method as the key and the path as the value.</p>
<p>I am sure I will have good reason to change and rethink the above above points as I design other APIs in the future but for this application it has worked really well. And each of the above points are important to think about when defining a REST API, weather the conclusions are the same or not.</p>
 <p><a href="http://www.tomasmalmsten.com/?flattrss_redirect&amp;id=768&amp;md5=73602d3b3fb91c10dee428937e2ec26a" title="Flattr" target="_blank"><img src="http://www.tomasmalmsten.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.tomasmalmsten.com/2011/11/creating-links-rest-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=tomasmalmsten&amp;popout=1&amp;url=http%3A%2F%2Fwww.tomasmalmsten.com%2F2011%2F11%2Fcreating-links-rest-api%2F&amp;language=en_GB&amp;category=software&amp;title=Designing+a+HATEOAS+REST+API&amp;description=I+have+recently+finished+designing+a+REST+protocol.+There+are+a+few+things+that+needs+careful+consideration+when+exposing+a+domain+through+such+an+interface.+I+will+gather+some+of...&amp;tags=Architecture%2CREST%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Valuable returns for writing Clean Code</title>
		<link>http://www.tomasmalmsten.com/2011/11/returns-writing-clean-code/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.tomasmalmsten.com/2011/11/returns-writing-clean-code/#comments</comments>
		<pubDate>Wed, 02 Nov 2011 15:09:35 +0000</pubDate>
		<dc:creator>Tomas Malmsten</dc:creator>
				<category><![CDATA[Clean code]]></category>
		<category><![CDATA[clean code]]></category>

		<guid isPermaLink="false">http://www.tomasmalmsten.com/?p=760</guid>
		<description><![CDATA[<p>In the project I am currently working on I have a lot of code to write. It&#8217;s a green field project delivering a new platform and I have no frameworks to borrow from or extend. So I have to write the code for each single feature by hand. I am not complaining. I like writing [...]</p>
 ]]></description>
			<content:encoded><![CDATA[<p>In the project I am currently working on I have a lot of code to write. It&#8217;s a green field project delivering a new platform and I have no frameworks to borrow from or extend. So I have to write the code for each single feature by hand.</p>
<p>I am not complaining. I like writing code. But it takes time, especially since it&#8217;s only me on the project at the moment.</p>
<p>Thankfully it&#8217;s all written in Python so it&#8217;s not to verbose, though even Python is verbose when you have to write this amount of repetitive code.</p>
<p>Which is how we come to the value of clean code. The code is slowly transforming by refactoring and <a href="http://cleancoder.posterous.com/the-transformation-priority-premise" target=_blank">transformations</a>. The effect of this is that there is no repetition in production code, it is completely DRY. In tests there is little repetition, this to make the tests document the production code.</p>
<p>The effect of this is that although the upfront cost, before any abstractions had been created, was slightly higher the cost of adding new features now is very small. To create a function that initially required 40 lines of code excluding tests now requires 5 to 10 lines. The test abstractions are so easy to use that it takes next to no time even though some repetition (sequentially calling the same methods in each test method to explain the steps required to use the function) is needed.</p>
<p>The conclusion to this is that the returns of clean code is rather immediate. Many seems to think that the returns are slow and far in the future. I know this to be the opposite. The returns are almost immediate and are currently cutting development time radically. And that is on a code base which has only a couple of thousand lines of production code.</p>
 <p><a href="http://www.tomasmalmsten.com/?flattrss_redirect&amp;id=760&amp;md5=8a88a51fc8e3728bccb25b1f388f7879" title="Flattr" target="_blank"><img src="http://www.tomasmalmsten.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.tomasmalmsten.com/2011/11/returns-writing-clean-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=tomasmalmsten&amp;popout=1&amp;url=http%3A%2F%2Fwww.tomasmalmsten.com%2F2011%2F11%2Freturns-writing-clean-code%2F&amp;language=en_GB&amp;category=software&amp;title=Valuable+returns+for+writing+Clean+Code&amp;description=In+the+project+I+am+currently+working+on+I+have+a+lot+of+code+to+write.+It%26%238217%3Bs+a+green+field+project+delivering+a+new+platform+and+I+have+no+frameworks...&amp;tags=clean+code%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Test coverage statistics with nosetests</title>
		<link>http://www.tomasmalmsten.com/2011/10/test-coverage-statistics-run-nosetests/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.tomasmalmsten.com/2011/10/test-coverage-statistics-run-nosetests/#comments</comments>
		<pubDate>Wed, 26 Oct 2011 09:19:02 +0000</pubDate>
		<dc:creator>Tomas Malmsten</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[clean code]]></category>
		<category><![CDATA[nosetests]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://www.tomasmalmsten.com/?p=742</guid>
		<description><![CDATA[<p>I use nosetests when running my python tests. It is a really neat little tool that will automatically discover and run all tests in the project with one single command line command &#8211; nosetests. But it has more neatness then this. With a simple option it will also print test coverage for the project: --with-coverage, [...]</p>
 ]]></description>
			<content:encoded><![CDATA[<p>I use nosetests when running my python tests. It is a really neat little tool that will automatically discover and run all tests in the project with one single command line command &#8211; nosetests.</p>
<p>But it has more neatness then this. With a simple option it will also print test coverage for the project: <code>--with-coverage</code>, and if coverage should be calculated base on specific packages then use <code>--cover-package</code> which takes a list of packages to calculate coverage on. This is useful when there are library packages for a virtual env or similar within the same directory as you run nose.</p>
<p>I don&#8217;t like to leave lose ends so to ensure that there are no lingering compiled *.pyc files sitting around I run the following script before commit:</p><pre class="crayon-plain-tag">#!/bin/sh
#find all .pyc files and remove them
find &lt;source-dir&gt; ... &lt;source-dir&gt; -name '*.pyc' -exec rm {} \;
#Execute tests
nosetests --with-coverage --cover-package=&lt;package&gt;</pre><p>Where &lt;source-dir&gt; should be replaced with directories where source files are. This is a space delimited list. And &lt;package&gt; is replaced with packages which should have coverage statistics calculated.</p>
 <p><a href="http://www.tomasmalmsten.com/?flattrss_redirect&amp;id=742&amp;md5=56b318c75d1d65b835d4f5080498bb9f" title="Flattr" target="_blank"><img src="http://www.tomasmalmsten.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.tomasmalmsten.com/2011/10/test-coverage-statistics-run-nosetests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=tomasmalmsten&amp;popout=1&amp;url=http%3A%2F%2Fwww.tomasmalmsten.com%2F2011%2F10%2Ftest-coverage-statistics-run-nosetests%2F&amp;language=en_GB&amp;category=software&amp;title=Test+coverage+statistics+with+nosetests&amp;description=I+use+nosetests+when+running+my+python+tests.+It+is+a+really+neat+little+tool+that+will+automatically+discover+and+run+all+tests+in+the+project+with+one+single+command...&amp;tags=clean+code%2Cnosetests%2Cpython%2Cshell%2Ctdd%2Ctesting%2Cunit+testing%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Keeping your Python code DRY using Clone Digger</title>
		<link>http://www.tomasmalmsten.com/2011/10/keeping-python-code-dry-clone-digger/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.tomasmalmsten.com/2011/10/keeping-python-code-dry-clone-digger/#comments</comments>
		<pubDate>Fri, 21 Oct 2011 11:08:23 +0000</pubDate>
		<dc:creator>Tomas Malmsten</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[clean code]]></category>
		<category><![CDATA[DRY]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.tomasmalmsten.com/?p=722</guid>
		<description><![CDATA[<p>DRY (as in Don&#8217;t Repeat Yourself) is one of the corner stones of a clean and agile code. This is especially so with the production code but also with test code where finding good abstractions will greatly increase speed and lower maintenance. When working with python I have found a very nice tool called Clone [...]</p>
 ]]></description>
			<content:encoded><![CDATA[<p>DRY (as in Don&#8217;t Repeat Yourself) is one of the corner stones of a clean and agile code. This is especially so with the production code but also with test code where finding good abstractions will greatly increase speed and lower maintenance.</p>
<p>When working with python I have found a very nice tool called <a hre="http://clonedigger.sourceforge.net/" target="_blank">Clone Digger</a> that helps finding repetitions in code. It is easy to set up and work with and the report is clear and easy to read.</p>
<p>Install it with pip:</p><pre class="crayon-plain-tag">pip install clonedigger</pre><p></p>
<p>When installed it is automatically added to the tool chain. To run it use the following command:</p><pre class="crayon-plain-tag">clonedigger package</pre><p>Package is the directory where the python code is to be found. Clone digger takes a list of packages separated with space. &#8211;help will show help on options and configuration.</p>
<p>Clone digger will work it&#8217;s way through all files in each package and compare them, both within each package and across package listed in the same invocation. If there is code, such as auto generated code, that is not modifiable, it needs to be removed from the packages added in order for the tool not to analyse them.</p>
<p>It will generate a report looking like the one below to output.html (this is configurable).</p>
<p><a href="http://www.tomasmalmsten.com/wp-content/uploads/2011/10/Screen-shot-2011-10-21-at-12.43.52-PM.png#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img src="http://www.tomasmalmsten.com/wp-content/uploads/2011/10/Screen-shot-2011-10-21-at-12.43.52-PM-300x232.png" alt="Clone Digger output" title="Clone Digger output" width="300" height="232" class="alignnone size-medium wp-image-737" /></a></p>
<p>Working with tools like this makes it easy to spot where new abstractions should be added to remove code duplication. Both in test and production code. Where ever repetition is found which does not fill an important documenting function (which is sometimes the case in tests) it is easy to spot where and how a method should be added to pull the functionality together. It will also help in naming such methods. There are of cause some false positives. Especially in the test code where method bodies are often descriptive rather then dry. But even here it helps to find common assertions which can be pulled up and made into new descriptive methods. This becomes especially valuable when working with given-when-then in tests.</p>
 <p><a href="http://www.tomasmalmsten.com/?flattrss_redirect&amp;id=722&amp;md5=8b0884b984398be93053f9979e766260" title="Flattr" target="_blank"><img src="http://www.tomasmalmsten.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.tomasmalmsten.com/2011/10/keeping-python-code-dry-clone-digger/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=tomasmalmsten&amp;popout=1&amp;url=http%3A%2F%2Fwww.tomasmalmsten.com%2F2011%2F10%2Fkeeping-python-code-dry-clone-digger%2F&amp;language=en_GB&amp;category=software&amp;title=Keeping+your+Python+code+DRY+using+Clone+Digger&amp;description=DRY+%28as+in+Don%26%238217%3Bt+Repeat+Yourself%29+is+one+of+the+corner+stones+of+a+clean+and+agile+code.+This+is+especially+so+with+the+production+code+but+also+with+test...&amp;tags=clean+code%2CDRY%2Cpython%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Choosing between table mappers or DeclerativeBase when working with SQLAlchemy</title>
		<link>http://www.tomasmalmsten.com/2011/10/choosing-table-mappers-declerativebase-working-sqlalchemy/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.tomasmalmsten.com/2011/10/choosing-table-mappers-declerativebase-working-sqlalchemy/#comments</comments>
		<pubDate>Tue, 18 Oct 2011 11:56:18 +0000</pubDate>
		<dc:creator>Tomas Malmsten</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[clean code]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[Design patterns]]></category>
		<category><![CDATA[ORM]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[SQLAlchemy]]></category>

		<guid isPermaLink="false">http://www.tomasmalmsten.com/?p=695</guid>
		<description><![CDATA[<p>I have recently been looking how to create a clean Domain Driven Design architecture using SQLAlchemy and specifically how to map domain classes to tables. This post will discuss the two techniques available and why to choose one over the other. Lets start with looking at the two strategies available. SQLAlchemy offers a Data Mapper [...]</p>
 ]]></description>
			<content:encoded><![CDATA[<p>I have recently been looking how to create a clean Domain Driven Design architecture using <a href="http://www.sqlalchemy.org/" target="_blank">SQLAlchemy</a> and specifically how to map domain classes to tables. This post will discuss the two techniques available and why to choose one over the other.</p>
<p>Lets start with looking at the two strategies available. SQLAlchemy offers a <a href="http://martinfowler.com/eaaCatalog/dataMapper.html" target="_blank">Data Mapper</a> out of the box. It is also possible to use an <a href="http://martinfowler.com/eaaCatalog/activeRecord.html" target="_blank">Active Record</a> approach by using the <a href="http://www.sqlalchemy.org/docs/orm/extensions/declarative.html" target="_blank">Declarative Base</a> ORM extension.</p>
<p>The Active Record approach is a very attractive way of working. It adds metadata to the domain objects that tells the engine how to save them to the database. It&#8217;s quick and easy to use and avoids extra classes or configurations that handles the database mapping. It&#8217;s a perfect fit for most web applications. The main drawback is that storage logic is tightly coupled with the domain objects. This can make the domain difficult to work with over time. It also means that any changes required in storage logic will force changes into the domain breaking the <a href="http://en.wikipedia.org/wiki/Single_responsibility_principle" target="_blank">Single Responsibility Principle</a>. Active Record will also prove very costly if the project finds that a change of storage technology would be beneficial. A not to unlikely event with such a variation in industry strength storage technologies available.</p>
<p>Data Mappers provides high decoupling by keeping all meta data for mapping objects to tables separate from the domain. The mapping can be placed in its own module which makes it easy to divide the domain into coherent modules with no need to cater for storage concerns. It also makes it easy to model more advanced relational concepts in a large database. Since it allows for complete separation of concerns for domain and data access it is also easy to change or swap out the data storage technology completely without any needs to change the domain. It does however increase the complexity of the application since it adds an extra module/package.</p>
<p>If the project in question is going to use a clean implementation of Domain Driven Design only the Data Mapper works. It is also the only possible choice if it is likely that the project will be changing storage technology.</p>
<p>If, however, the project is a traditional web application with a domain model that is simple or close to non-existing then Active Record is a good choice. It will provide more speed of development. Making a clear distinction between domain logic tests and data access tests will make it easier to later extract data access out into Data Mappers if needed.</p>
 <p><a href="http://www.tomasmalmsten.com/?flattrss_redirect&amp;id=695&amp;md5=9ed564fe38f13590eb10cb9fb2105106" title="Flattr" target="_blank"><img src="http://www.tomasmalmsten.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.tomasmalmsten.com/2011/10/choosing-table-mappers-declerativebase-working-sqlalchemy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=tomasmalmsten&amp;popout=1&amp;url=http%3A%2F%2Fwww.tomasmalmsten.com%2F2011%2F10%2Fchoosing-table-mappers-declerativebase-working-sqlalchemy%2F&amp;language=en_GB&amp;category=software&amp;title=Choosing+between+table+mappers+or+DeclerativeBase+when+working+with+SQLAlchemy&amp;description=I+have+recently+been+looking+how+to+create+a+clean+Domain+Driven+Design+architecture+using+SQLAlchemy+and+specifically+how+to+map+domain+classes+to+tables.+This+post+will+discuss+the...&amp;tags=clean+code%2CDDD%2CDesign+patterns%2CORM%2Cpython%2CSQLAlchemy%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Vanilla Daiquiri</title>
		<link>http://www.tomasmalmsten.com/2011/09/vanilla-daiquiri/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.tomasmalmsten.com/2011/09/vanilla-daiquiri/#comments</comments>
		<pubDate>Thu, 01 Sep 2011 18:37:05 +0000</pubDate>
		<dc:creator>Tomas Malmsten</dc:creator>
				<category><![CDATA[Mixology]]></category>
		<category><![CDATA[Cocktail]]></category>
		<category><![CDATA[Daiquiri]]></category>
		<category><![CDATA[Rum]]></category>

		<guid isPermaLink="false">http://www.tomasmalmsten.com/?p=685</guid>
		<description><![CDATA[<p>We&#8217;ve had some good friends to visit over the weekend and of course drunk many good cocktails. One of them was an especially nice daiquiri which I named Vanilla Daiquiri. It is based on the Embury&#8217;s 8:2:1 formula but instead of using simple syrup I used Monin&#8217;s Vanilla Syrup. This makes for a lovely smooth [...]</p>
 ]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve had some good friends to visit over the weekend and of course drunk many good cocktails. One of them was an especially nice daiquiri which I named Vanilla Daiquiri.</p>
<p>It is based on the Embury&#8217;s 8:2:1 formula but instead of using simple syrup I used Monin&#8217;s Vanilla Syrup. This makes for a lovely smooth vanilla infused daiquiri.</p>
<p>Recipe:<br />
2 shots Ron Barceló rum<br />
1/2 shot lime juice<br />
1/4 shot Monin Vanilla syrup</p>
<p>Pour all ingredients into shaker. Shake well, and if you are using big blocks of ice allow to dilute a little extra. Fine strain into cocktail glas and garnish with a lime wedge on the rim.</p>
<p>Enjoy!</p>
 <p><a href="http://www.tomasmalmsten.com/?flattrss_redirect&amp;id=685&amp;md5=45eb0dd8d6b38796215aeb019c75c9f0" title="Flattr" target="_blank"><img src="http://www.tomasmalmsten.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.tomasmalmsten.com/2011/09/vanilla-daiquiri/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=tomasmalmsten&amp;popout=1&amp;url=http%3A%2F%2Fwww.tomasmalmsten.com%2F2011%2F09%2Fvanilla-daiquiri%2F&amp;language=en_GB&amp;category=text&amp;title=Vanilla+Daiquiri&amp;description=We%26%238217%3Bve+had+some+good+friends+to+visit+over+the+weekend+and+of+course+drunk+many+good+cocktails.+One+of+them+was+an+especially+nice+daiquiri+which+I+named+Vanilla+Daiquiri....&amp;tags=Cocktail%2CDaiquiri%2CRum%2Cblog" type="text/html" />
	</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  www.tomasmalmsten.com/feed/ ) in 1.06637 seconds, on May 20th, 2012 at 1:30 am UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on May 20th, 2012 at 2:30 am UTC -->
