<?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>Alexandre Martins &#187; Programming</title>
	<atom:link href="http://blog.m.artins.net/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.m.artins.net</link>
	<description>On Agile Software Development</description>
	<lastBuildDate>Thu, 12 Aug 2010 20:09:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>TDD: Listen to the tests&#8230; they tell smells in your code!</title>
		<link>http://blog.m.artins.net/tdd-listen-to-the-tests-they-tell-smells-in-your-code/</link>
		<comments>http://blog.m.artins.net/tdd-listen-to-the-tests-they-tell-smells-in-your-code/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 02:30:11 +0000</pubDate>
		<dc:creator>Alexandre Martins</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Object-Oriented Programming]]></category>
		<category><![CDATA[Test-Driven Development]]></category>

		<guid isPermaLink="false">http://blog.m.artins.net/?p=305</guid>
		<description><![CDATA[These days, reading the Goos book, by Steve Freeman and Nat Pryce, it reminded me of a project I worked on a while ago. It was a one year old system, poorly tested, integrating to a handful of other systems, and the code-base... well I prefer not to remember. Despite this scenario, I joined the [...]]]></description>
			<content:encoded><![CDATA[<p>These days, reading the <strong><a href="http://www.amazon.com/Growing-Object-Oriented-Software-Guided-Tests/dp/0321503627">Goos</a></strong> book, by <a href="http://www.m3p.co.uk/blog/">Steve Freeman</a> and <a href="http://www.natpryce.com/">Nat Pryce</a>, it reminded me of a project I worked on a while ago. It was a one year old system, poorly tested, integrating to a handful of other systems, and the code-base... well I prefer not to remember. Despite this scenario, I joined the team to help them implement some new functionalities.</p>
<p>I remember sometimes it was difficult to write tests, the classes were tightly coupled, with no clear responsibilities, several attributes, bloated constructors, etc. And despite our best effort, working around the bits that were preventing us from writing the tests, we felt we were getting down the wrong road, trying to do it in such a crappy code-base. As a result some of our tests were massive! A bunch of lines of mocks, stubs, and expectations, making it impossible to understand their purpose.</p>
<h2>What have I learned?</h2>
<p>Reading one of the book chapters I learned that the same qualities that makes an object easy to test also makes the code responsive to change. In my situation, the tests were telling me how clumsy the code was and how difficult it would be to extend it.</p>
<p>I also learned that when we come across a functionality that is difficult to test,   asking ourselves <strong><em>how</em></strong> to test it is not enough, we also have to ask <strong><em>why</em></strong> is it difficult to test, and check whether it's an opportunity to improve our code. The trick is to do it driven by tests, so we can get rapid feedback on code's internal qualities and on whether it's doing what it's supposed to do.</p>
<p>So they introduced a variation for the well-known TDD cycle— <strong>"<em>Write a failing test</em>" =&gt; "<em>Make the test pass</em>" =&gt; "<em>Refactor</em>"</strong>. As described on the figure below (extracted from the book), if we're finding it hard to write the next failing test for our application, we should look again at the design of the production code and often refactor it before moving on, until we get to the point that we can write tests that reads well.</p>
<div style="text-align: center;"><img style="border: 0px none;" src="http://blog.m.artins.net/wp-content/uploads/2010/07/listen-to-tests.png" alt="" width="306" height="226" /></div>
<p><cite>Extracted from Growing Object-Oriented Software, Guided By Tests— Steve Freeman and Nat Pryce</cite></p>
<h2>An Example of a Smell Tests Might Be Telling You</h2>
<h3>Reference data rather than behavior</h3>
<p>When applying "<a href="http://pragprog.com/articles/tell-dont-ask">Tell Don't Ask</a>" or "<a href="http://pragprog.com/articles/tell-dont-ask">Law of Demeter</a>" consistently, we end up with a coding style where we tend to pass behavior into the system instead of pulling values up through the stack. So picking up the famous <em><strong>Paperboy</strong></em> example, before refactoring the code applying the "Law of Demeter" the code and test would look something along the lines of the snippet showed below.</p>
<pre style="background-color: #ffffe3; border-left: solid gray 4px; padding: 8px; margin-bottom: 10px; font-family: Courier New; font-size: 12px;">class Paperboy
  def collect_money(customer, due_amount)
    if due_amount &gt; customer.wallet.cash
      raise InsuficientFundsError
    else
      customer.wallet.cash -= due_amount
      @total_collected += due_amount
    end
  end
end
</pre>
<pre style="background-color: #ffffe3; border-left: solid gray 4px; padding: 8px; margin-bottom: 10px; font-family: Courier New; font-size: 12px;">it "should collect money from customer" do
  customer = Customer.new :wallet =&gt; Wallet.new(:amount =&gt; 200)
  paperboy = Paperboy.new
  paperboy.total_collected.should == 0
  paperboy.collect_money(customer, 50)
  customer.wallet.cash.should == 150
  paperboy.total_collected.should == 50
end
</pre>
<p>We can easily see that the test is telling us it knows too much detail about <span style="font-family: Courier New; font-size: 12px;">Customer</span> class implementation. We can see its internals, which objects it's related to, and even worse, we're also exposing implementation details of its peers. So it's clear for me that it needs some design improvement. My main goal here is to hide <span style="font-family: Courier New; font-size: 12px;">Customer</span> implementation details from the users of the <span style="font-family: Courier New; font-size: 12px;">Paperboy</span> class. Which means that I don't wanna see anything but <span style="font-family: Courier New; font-size: 12px;">Customer</span> and <span style="font-family: Courier New; font-size: 12px;">Money</span> classes referenced on the test!</p>
<pre style="background-color: #ffffe3; border-left: solid gray 4px; padding: 8px; margin-bottom: 10px; font-family: Courier New; font-size: 12px;">class Paperboy
  def collect_money(customer, due_amount)
    @collected_amount += customer.pay(due_amount)
  end
end
</pre>
<pre style="background-color: #ffffe3; border-left: solid gray 4px; padding: 8px; margin-bottom: 10px; font-family: Courier New; font-size: 12px;">it "should collect money from customer" do
  customer = Customer.new :total_cash =&gt; 200
  paperboy = Paperboy.new
  paperboy.total_collected.should == 0
  paperboy.collect_money(customer, 50)
  customer.total_cash.should == 150
  paperboy.total_collected.should == 50
end
</pre>
<p>The method <strong>customer.pay(due_amount)</strong> wraps all the implementation detail up behind a single call. The client of paperboy no longer needs to know anything about the types in the chain. We've reduced the risk that a design change might cause ripples in remote parts of the codebase.</p>
<p>As well as hiding information, there's a more subtle benefit from "Tell, Don't Ask." It forces us to make explicit and so name the interactions between objects, rather than leaving them implicit in the chain of getters. The shorter version above is much clearer about <em><strong>what</strong></em> it's for, not just <em><strong>how</strong></em> it happens to be implemented.</p>
<p>All the logic necessary to collect the money is inside the <span style="font-family: Courier New; font-size: 12px;">Customer</span> object, so it doesn't have to expose its state to its peers.</p>
<p>Now it's safer to continue writing new failing tests to our objects.<br />
Remember, listen to the tests!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.m.artins.net/tdd-listen-to-the-tests-they-tell-smells-in-your-code/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Hamcrest: Improving Reducer Implementations</title>
		<link>http://blog.m.artins.net/hamcrest-improving-reducer-implementations/</link>
		<comments>http://blog.m.artins.net/hamcrest-improving-reducer-implementations/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 13:22:00 +0000</pubDate>
		<dc:creator>Alexandre Martins</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.m.artins.net/?p=253</guid>
		<description><![CDATA[In the beginning of the year I posted about the ways you can use Hamcrest out of test code, together with hamcrest-collections. This combination allows us to write different kinds of matchers to select and reject items from lists, as well as applying map and reduce to them. After a while making use of them [...]]]></description>
			<content:encoded><![CDATA[<p>In the beginning of the year I posted about the ways you can use <a href="http://blog.m.artins.net/hamcrest-out-of-test-code">Hamcrest out of test code</a>, together with hamcrest-collections. This combination allows us to write different kinds of matchers to select and reject items from lists, as well as applying map and reduce to them. After a while making use of them on my current project, I wanted to share what I liked a lot, and what I didn't like a lot. My friend <a href="http://lizdouglass.wordpress.com">Liz Douglass</a> has also written a <a href="http://lizdouglass.wordpress.com/2009/09/07/lists-maps-etc">post sharing our experience</a>, and I will just complement it a bit...</p>
<h2>What I Liked A Lot</h2>
<p>There's no much to write here, as we all know that this combination is quite powerful when you're looking for writing code that reads more like english language, making it much easier to express the intent of your code. Not to mention that we get rid of for loops everywhere in the codebase.</p>
<h2>What I Didn't Liked A Lot</h2>
<p>One aspect I didn't like since the beginning when implementing Reducers is that they are coupled to one specific type. It reduces a list of one type into a result of the same type. And from the <a href="http://en.wikipedia.org/wiki/MapReduce">Wikipedia definition of Map and Reduce</a>... </p>
<p><cite><br />
<strong>"Map" step:</strong> The master node takes the input, chops it up into smaller sub-problems, and distributes those to worker nodes.<br />
</cite></p>
<p><cite><br />
<strong>"Reduce" step:</strong> The master node then takes the answers to all the sub-problems and combines them in a way to get the output - the answer to the problem it was originally trying to solve.<br />
</cite></p>
<p>... we can see that it doesn't mention that the result should be of the same type as the original one, after applying the reducer. And that's exactly what I wanted to do instead. People said I was trying to combine both Map and Reduce into a single implementation. I kind of disagree with that, because the fact that I am reducing a list into a result of a different type, it doesn't mean that I am transforming the original input (like multiplying each item in a list of integers by 2, before concatenating them). Confusing?</p>
<p>Let me try to explain it using an example. Given we have a list of integers...</p>
<pre style="border: solid gray 1px; width: 90%; padding: 10px;">
List<Integer> list = Lists.create(1, 2, 3);
</pre>
<p>and that I want to concatenate these numbers into a string. With the current <a href="http://code.google.com/p/hamcrest-collections">hamcrest-collections</a> implementation, that would be possible doing something like...</p>
<pre style="border: solid gray 1px; width: 90%; padding: 10px;">
Iterable<String> listOfStrings = FunctionMapper.map(list, new Function<Integer, String>() {
    public String apply(Integer number) {
        return String.valueOf(number);
    }
});

String result = Reduction.reduce(listOfStrings, new Reducer<String>() {
    public String apply(String first, String previous) {
        return first.concat("+").concat(previous);
    }
});

Assert.assertEquals("1+2+3", result);
</pre>
<p>It's quite a lot of code just to concatenate a list of numbers! One day while pairing with <a href="http://watchitlater.com/blog">Tom Czarniecki</a>, we decided to reimplement the <a href="http://code.google.com/p/hamcrest-collections/source/browse/trunk/hamcrest-collections/src/org/hamcrestcollections/Reduction.java">Reduction</a> and <a href="http://code.google.com/p/hamcrest-collections/source/browse/trunk/hamcrest-collections/src/org/hamcrestcollections/Reducer.java">Reducer</a> classes, so that we could create more flexible and simple Reducer implementations, and of course writing almost half the lines of code.</p>
<pre style="border: solid gray 1px; width: 90%; padding: 10px;">
public interface Reducer<T, U> {
    U apply(T first, U previous);
}
</pre>
<pre style="border: solid gray 1px; width: 90%; padding: 10px;">
public class Reduction {

    public static <T, U> U reduce(List<T> list, U initialValue, Reducer<T, U> reducer) {
        U currentValue = initialValue;
        for (T item : list) {
            currentValue = reducer.apply(item, currentValue);
        }
        return currentValue;
    }
}
</pre>
<p>To do the same number concatenation with this new implementation, is just a matter of defining a new Reducer, that concatenates them in a string.</p>
<pre style="border: solid gray 1px; width: 90%; padding: 10px;">
Assert.assertEquals("1+2+3", Reduction.reduce(list, "", new Reducer<Integer, String>() {
    public String apply(Integer first, String previous) {
        return previous.concat("+").concat(String.valueOf(first));
    }
}));
</pre>
<p>Much simpler!</p>
<h3>Advantages Of This New Implementation</h3>
<ol>
<li>Do I have to mention again that it's much cleaner?</li>
<li>We use java.util.List instead of Iterable.</li>
<li>No exception is thrown if the list to reduce is empty. It just uses the initial value provided on the reducer implementation.</li>
<li>Flexibility to reduce a list into a result of any type.</li>
</ol>
<p>Hope you enjoy it!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.m.artins.net/hamcrest-improving-reducer-implementations/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Hamcrest Out Of Test Code!</title>
		<link>http://blog.m.artins.net/hamcrest-out-of-test-code/</link>
		<comments>http://blog.m.artins.net/hamcrest-out-of-test-code/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 12:38:30 +0000</pubDate>
		<dc:creator>Alexandre Martins</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Behaviour-Driven Development]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Domain-Driven Design]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://blog.m.artins.net/?p=168</guid>
		<description><![CDATA[It's been a while since I read some interesting posts showing creative uses of Hamcrest library out of test code. Since then I've been proscrastinating to implement my own version, trying strongly typed java delegates. Thankfully this week I came across a nice API called hamcrest-collections. It uses Hamcrest to implement features such as select, [...]]]></description>
			<content:encoded><![CDATA[<p>It's been a while since I read <a href="http://joe.truemesh.com/blog/000705.html">some</a> <a href="http://jroller.com/ghettoJedi/entry/using_hamcrest_for_iterators">interesting</a> <a href="http://cromwellian.blogspot.com/2006/07/fun-with-generics-and-cglib-functional.html">posts</a> showing creative uses of <a href="http://code.google.com/p/hamcrest/">Hamcrest</a> library out of test code. Since then I've been proscrastinating to implement my own version, trying <a href="http://weblogs.java.net/blog/alexwinston/archive/2005/04/strongly_types_1.html">strongly typed java delegates</a>. </p>
<p>Thankfully this week I came across a nice API called <a href="http://code.google.com/p/hamcrest-collections/">hamcrest-collections</a>. It uses Hamcrest to implement features such as <strong><code>select</code></strong>, <strong><code>reject</code></strong>, <strong><code>map</code></strong>, <strong><code>reduce</code></strong> and <strong><code>zip</code></strong> familiar from languages like Ruby and Python. </p>
<h2>Selectors</h2>
<p>Selectors can be used to select or reject items that matches a given Matcher, from any iterable object. It reminds me the <a href="http://martinfowler.com/apsupp/spec.pdf">Specification Pattern</a> from <a href="http://domaindrivendesign.org/">Domain-Driven Design</a>, which is also used for querying objects that satisfies defined specifications.</p>
<pre style="border: solid gray 1px; width: 90%; padding: 10px;">
public static final Person john = new Person("John", 28);
public static final Person nicole = new Person("Nicole", 12);
public static final Person ryan = new Person("Ryan", 23);
public static final Person nathan = new Person("Nathan", 18);

public static final List<Person> list() {
    return Arrays.asList(john, nicole, ryan, nathan);
}</pre>
<p><br/><br />
The code below selects from the list of users defined above, the ones that are under twenty.</p>
<pre style="border: solid gray 1px; width: 90%; padding: 10px;">
@Test
public void should_select_only_people_under_twenty_years_old() {
    List<Person> users = Person.list();
    Iterable<Person> underTwentyList = select(users, underAge(20));
    assertThat(underTwentyList, hasItems(nicole, nathan));
    assertThat(underTwentyList, not(hasItems(john, ryan)));
}
</pre>
<p><br/><br />
The code below rejects all the users that are under twenty.</p>
<pre style="border: solid gray 1px; width: 90%; padding: 10px;">
@Test
public void should_reject_every_people_under_twenty_years_old() {
    List<Person> users = Person.list();
    Iterable<Person> aboveTwentyList = reject(users, underAge(20));
    assertThat(aboveTwentyList, hasItems(john, ryan));
    assertThat(aboveTwentyList, not(hasItems(nicole, nathan)));
}</pre>
<p><br/></p>
<h2>Map and Reduce</h2>
<p>Map is used to apply a function onto each item in any iterable object, whereas Reduce combines all these elements, applying a Reducer implementation. In our example, we map the timesTwo function, that doubles each element in the list, and then we reduce it by adding up all of them.</p>
<pre style="border: solid gray 1px; width: 90%; padding: 10px;">
@Test
public void should_double_each_number_in_the_list_then_sum_all_of_them() {
    List<Integer> numbers = Arrays.asList(1, 2, 3);
    MultiplyBy timesTwo = new MultiplyBy(2);

    Iterable<Integer> result = map(numbers, timesTwo);
    assertThat(result, hasItems(2, 4, 6));

    Integer sum = reduce(result, new Sum());
    assertThat(sum, equalTo(12));
}</pre>
<p><br/></p>
<pre style="border: solid gray 1px; width: 90%; padding: 10px;">
public class MultiplyBy implements Function<Integer, Integer> {
    private Integer factor;

    public MultiplyBy(Integer factor) {
        this.factor = factor;
    }

    public Integer apply(Integer number) {
        return (int)number * factor;
    }
}</pre>
<p><br/></p>
<pre style="border: solid gray 1px; width: 90%; padding: 10px;">
public class Sum implements Reducer<Integer> {
    public Integer apply(Integer first, Integer second) {
        return first + second;
    }
}</pre>
<p><br/></p>
<p>Despite the bias created by some developers, that Hamcrest should not be used anywhere else but test code, specially after JUnit has defined it as its new matcher library, just ignore it and add these features to your runtime library, so that you can let your creativity drive you when developing. Get rid of "for" loops from your life! <img src='http://blog.m.artins.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.m.artins.net/hamcrest-out-of-test-code/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Clojure: Integrating With Java</title>
		<link>http://blog.m.artins.net/clojure-integrating-with-java/</link>
		<comments>http://blog.m.artins.net/clojure-integrating-with-java/#comments</comments>
		<pubDate>Thu, 01 Jan 2009 06:44:04 +0000</pubDate>
		<dc:creator>Alexandre Martins</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Clojure]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.m.artins.net/?p=145</guid>
		<description><![CDATA[Currently I am learning Clojure. It is a functional programming language, but not a pure one, since you can both write code that share state (mutable) and also ones that doesn't. Why Clojure? The main reason why I chose Clojure is its easy interoperability with Java, still one of the most used languages, bringing to [...]]]></description>
			<content:encoded><![CDATA[<p>Currently I am learning <a href="http://clojure.org/">Clojure</a>. It is a functional programming language, but not a <a href="http://en.wikipedia.org/wiki/Purely_functional">pure one</a>, since you can both write code that share state (mutable) and also ones that doesn't.</p>
<h2>Why Clojure?</h2>
<p>The main reason why I chose Clojure is its easy interoperability with <a href="http://java.com">Java</a>, still one of the most used languages, bringing to it the power of Lisp. It's fast, since the code is compiled, and it supplements some of Java's weakness, such as the Collections framework and concurrent programming. It is pretty straightforward to write concurrent programs, everything is automatic, no manual lock management!</p>
<h2>Integrating With Java</h2>
<h3>Importing classes</h3>
<p>A single class:</p>
<pre style="border: solid gray 1px; width: 60%; padding: 5px;">
(import java.util.List)
</pre>
</p>
<p>Multiple classes from the same package:</p>
<pre style="border: solid gray 1px; width: 60%; padding: 5px;">
(import '(java.util List Set))
</pre>
</p>
<h3>Creating instances</h3>
<p>Using Java's <span style="font-family: courier;">new</span> keyword:</p>
<pre style="border: solid gray 1px; width: 60%; padding: 5px;">
(new java.util.ArrayList)
(new ArrayList) ; after importing
</pre>
</p>
<p>Assigning a new  <span style="font-family: courier;">List</span> to a Clojure variable:</p>
<pre style="border: solid gray 1px; width: 60%; padding: 5px;">
(def list (new java.util.List))
-> #'user/list
</pre>
</p>
<p>Syntactic Sugar:</p>
<pre style="border: solid gray 1px; width: 60%; padding: 5px;">
(ArrayList.)
</pre>
</p>
<h3>Accessing ﬁelds</h3>
<p>Static fields:</p>
<pre style="border: solid gray 1px; width: 60%; padding: 5px;">
(. Math PI)
</pre>
</p>
<p>Syntactic Sugar:</p>
<pre style="border: solid gray 1px; width: 60%; padding: 5px;">
Math/PI
</pre>
</p>
<h3>Invoking methods</h3>
<p>
<h4>Static Methods</h4>
<pre style="border: solid gray 1px; width: 60%; padding: 5px;">
(.currentTimeMillis System)
</pre>
</p>
<p>Syntactic Sugar:</p>
<pre style="border: solid gray 1px; width: 60%; padding: 5px;">
(System/currentTimeMillis)
</pre>
</p>
<p>
<h4>Non-static Methods</h4>
<pre style="border: solid gray 1px; width: 60%; padding: 5px;">
(. list size)
(. list get 0) ; returns the object stored at index 0
</pre>
</p>
<p>Syntactic Sugar:</p>
<pre style="border: solid gray 1px; width: 60%; padding: 5px;">
(.size list)
</pre>
</p>
<h3>Mixing Them All</h3>
<p>Clojure provides a macro called  <span style="font-family: courier;">memfn</span> that makes possible execute Java methods as functions. So, for a list of String objects, if I want to make all of them upper-case, all I have to do is:</p>
<pre style="border: solid gray 1px; width: 60%; padding: 5px;">
(map (memfn toUpperCase) ["a" "short" "message"])
</pre>
<p>The  <span style="font-family: courier;">map</span> function applies the function/method  <span style="font-family: courier;"> toUpperCase</span> to each element in  <span style="font-family: courier;">["a" "short" "message"]</span></p>
<p>You can also use the  <span style="font-family: courier;">bean</span> function to wrap a Java bean in an immutable Clojure map.</p>
<pre style="border: solid gray 1px; width: 60%; padding: 5px;">
(bean (new Person "Alexandre" "Martins"))
-> {:firstName "Alexandre", :lastName "Martins"}
</pre>
<p>Once converted, you can manipulate the new map using any of Clojure’s map functions, like:</p>
<pre style="border: solid gray 1px; width: 60%; padding: 5px;">
(:firstName (bean (new Person "Alexandre" "Martins")))
-> Alexandre
</pre>
<p>The code above extracts the <span style="font-family: courier;">firstName</span> key, originally from the  <span style="font-family: courier;">Person</span> object.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.m.artins.net/clojure-integrating-with-java/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Ping Pong Pairing: Even More Fun!</title>
		<link>http://blog.m.artins.net/ping-pong-pairing-even-more-fun/</link>
		<comments>http://blog.m.artins.net/ping-pong-pairing-even-more-fun/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 13:05:16 +0000</pubDate>
		<dc:creator>Alexandre Martins</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Coaching]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Pair Programming]]></category>
		<category><![CDATA[Test-Driven Development]]></category>

		<guid isPermaLink="false">http://blog.m.artins.net/?p=137</guid>
		<description><![CDATA[The agile software development practice I like the most, and at the same time, the one I find the most difficult is pair programming. Each individual has his/her own way of working, and characteristics such as motivation, engagement, habits, open-mindedness, and coding/design style varies a lot from individuals. Sometimes, to get a balance between these [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.m.artins.net/wp-content/uploads/2008/12/pingpong.jpg" style="border: 0px;" width="150" height="113" align="left" />The agile software development practice I like the most, and at the same time, the one I find the most difficult is pair programming. Each individual has his/her own way of working, and characteristics such as motivation, engagement, habits, open-mindedness, and coding/design style varies a lot from individuals. Sometimes, to get a balance between these differences is quite hard. I am still not an expert in pair programming coaching, but I've been learning a lot on my current assignment.</p>
<p>And from this experience, it seems that clients are definitely more involved and amused when it comes pairing following the ping pong pattern.</p>
<h3>Ping Pong Pattern</h3>
<p>It happens when the developer 1 from a pair implements a test for a given feature and see it failing, then passes the keyboard to developer 2 who makes the test pass, do some refactoring on the code and implements another test, passing the keyboard back to developer 1 to do the same thing and continue until the feature is done.</p>
<h3>Why Do We Like</h3>
<ul>
<li><strong>Challenge</strong> - Each time a developer writes a test for you to make it pass, it sounds like a challenge, then you do it and write another one, challenging him back.</li>
<li><strong>Dynamics</strong> - The worse thing is a developer that just hogs the keyboard, making you feel a useless. Ping pong pairing makes you swap keyboard more frequently.</li>
<li><strong>Engagement</strong> - Developers are much more engaged because they are constantly coding, not only observing.</li>
<li><strong>Fun</strong> - It is so much fun when you have all the above items together!</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.m.artins.net/ping-pong-pairing-even-more-fun/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Spring MVC, almost there!</title>
		<link>http://blog.m.artins.net/spring-mvc-almost-there/</link>
		<comments>http://blog.m.artins.net/spring-mvc-almost-there/#comments</comments>
		<pubDate>Tue, 30 Sep 2008 09:07:49 +0000</pubDate>
		<dc:creator>Alexandre Martins</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://blog.m.artins.net/?p=94</guid>
		<description><![CDATA[One of the things I really like about Spring 2.5 is the new set of annotations for defining controllers. Now you don't have to extend any superclass to turn your class into a controller, just add the @Controller annotation on the top of the class definition and that's it, you got one (still have to [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things I really like about <a href="http://www.springframework.org/">Spring 2.5</a> is the new set of annotations for defining controllers.<br />
Now you don't have to extend any superclass to turn your class into a controller, just add the <a href="http://static.springframework.org/spring/docs/2.0.x/api/org/springframework/web/portlet/mvc/Controller.html">@Controller</a> annotation on the top of the class definition and that's it, you got one (still have to define it as a bean in the XML file). Another cool feature in this set, is the combination of the <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/web/bind/annotation/RequestMapping.html">@RequestMapping</a> and <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/web/bind/annotation/RequestParam.html">@RequestParam</a> annotations.</p>
<pre name="code" class="java">
@Controller
public class ProductController {

	@Autowired
	private MemberRepository repository;

	@RequestMapping(value="/product", method=RequestMethod.GET)
	public String product(@RequestParam(value="id") String id, ModelMap model) {
		model.addAttribute("product", repository.getProduct(id));
		return "product/view";
	}
}
</pre>
<p><a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/web/bind/annotation/RequestMapping.html">@RequestMapping</a> gives you flexibility to map methods in the controller to whatever URIs and <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/web/bind/annotation/RequestMethod.html">HTTP methods</a> (default to <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/web/bind/annotation/RequestMethod.html#GET">RequestMethod.GET</a>) you like. They are not dependent on another or on controller's name. This really turns things easier when mapping your methods to <a href="http://en.wikipedia.org/wiki/RESTful">RESTful</a> URIs. The only downside in this implementation is that it doesn't allow you to pull out parameters from an URI. If you want to grab some data from the URL, you are going to have to do it the old fashioned way, like:</p>
<p><strong>mystore/product?id=123456</strong></p>
<p>But on the other hand the <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/web/bind/annotation/RequestParam.html">@RequestParam</a> annotation frees you from the dirty job of extracting parameters from a request. Thus, you don't even need to know about the <a href="http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpServletRequest.html">HttpServletRequest</a> and <a href="http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpServletResponse.html">HttpServletResponse</a> objects. To retrieve a parameter from a request, just add it as a method parameter and define it as a @RequestParam. The value attribute on the annotation should match the URL parameter name.</p>
<pre name="code" class="java">
@RequestMapping("/products")
public String products(@RequestParam(value="letter", required=false) String letter, ModelMap model) {
	checkLetter(letter);
	model.addAttribute("products", repository.getProducts(letter));
	return "product/list";
}
</pre>
<p>You also have the option of defining a request parameter as required or not (default set to required), so as in the example above, the method would be able to handle requests coming from both <strong>mystore/products</strong>, to list all existent products, and <strong>mystore/products?letter=A</strong>, to list all existent products starting with the letter 'A'. Really neat!</p>
<p>The good news is that Spring 3.0 is coming out next November, and it will include the URI templating functionality. According to <a href="http://www.springify.com/archives/16">Springify</a> blog, you will be able to define a URI like mystore/product/123456, and that will map to the controller method as follows:</p>
<pre name="code" class="java">
@RequestMapping("/product/${id}")
public String product(@RequestParam("id") String id, ModelMap model) {
	model.addAttribute("product", repository.getProduct(id));
	return "product/view";
}
</pre>
<p>So let's wait for it!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.m.artins.net/spring-mvc-almost-there/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Common Lisp, Erlang and Emacs (Leopard)</title>
		<link>http://blog.m.artins.net/common-lisp-erlang-and-emacs-leopard/</link>
		<comments>http://blog.m.artins.net/common-lisp-erlang-and-emacs-leopard/#comments</comments>
		<pubDate>Fri, 20 Jun 2008 05:40:22 +0000</pubDate>
		<dc:creator>Alexandre Martins</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Erlang]]></category>
		<category><![CDATA[MacOS]]></category>

		<guid isPermaLink="false">http://blog.m.artins.net/?p=37</guid>
		<description><![CDATA[This useful post from my friend Renato Lucindo is for those interested in start playing with Erlang. It helps you to set up your development environment, for MacOS, showing how to install it using MacPorts and how to set up Emacs. * It's in portuguese!]]></description>
			<content:encoded><![CDATA[<p>This <a href="http://blog.lucindo.com.br/2008/01/25/common-lisp-erlang-e-emacs-no-leopard/">useful post</a> from my friend <a href="http://blog.lucindo.com.br/">Renato Lucindo</a> is for those interested in start playing with <a href="http://www.erlang.org/">Erlang</a>. It helps you to set up your development environment, for MacOS, showing how to install it using <a href="http://www.macports.org/">MacPorts</a> and how to set up Emacs.<br />
<strong>* It's in portuguese!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.m.artins.net/common-lisp-erlang-and-emacs-leopard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Subversion command reference</title>
		<link>http://blog.m.artins.net/subversion-command-reference/</link>
		<comments>http://blog.m.artins.net/subversion-command-reference/#comments</comments>
		<pubDate>Wed, 02 Apr 2008 18:58:54 +0000</pubDate>
		<dc:creator>Alexandre Martins</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Reference]]></category>
		<category><![CDATA[Subversion]]></category>
		<category><![CDATA[SVN]]></category>

		<guid isPermaLink="false">http://blog.m.artins.net/?p=21</guid>
		<description><![CDATA[This post is more to keep in a single place reference to useful subversion commands, for future development. Anyone who has a command can comment this post, so I can add it here. List all your local files that hasn't been added to the repository yet. vn st &#124; grep ? Add all your local [...]]]></description>
			<content:encoded><![CDATA[<p>This post is more to keep in a single place reference to useful subversion commands, for future development.<br />
Anyone who has a command can comment this post, so I can add it here.</p>
<p>List all your local files that hasn't been added to the repository yet.</p>
<pre>vn st | grep ?</pre>
<p>Add all your local files that hasn't been added to the repository yet.</p>
<pre>svn st | grep ? | cut -b7- | xargs svn add</pre>
<p>or</p>
<pre>svn add . –force</pre>
<p>Send HTML formatted email messages for Subversion activity (see <a href="http://search.cpan.org/dist/SVN-Notify/">SVN-Notify</a> website)</p>
<pre>
svnnotify -d -H HTML::ColorDiff --smtp myhost.com
--repos-path "$1" --revision "$2" -t dev1@myhost.com -t dev2@myhost.com
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.m.artins.net/subversion-command-reference/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
