<?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>Shaun Abram</title>
	<atom:link href="http://www.shaunabram.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.shaunabram.com</link>
	<description>Java and Technology weblog</description>
	<lastBuildDate>Wed, 05 Jun 2013 19:10:19 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>ThoughtWorks Technology Radar</title>
		<link>http://www.shaunabram.com/thoughtworks-tech-radar/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=thoughtworks-tech-radar</link>
		<comments>http://www.shaunabram.com/thoughtworks-tech-radar/#comments</comments>
		<pubDate>Thu, 30 May 2013 06:28:07 +0000</pubDate>
		<dc:creator>sabram</dc:creator>
				<category><![CDATA[Products]]></category>
		<category><![CDATA[radar]]></category>
		<category><![CDATA[thoughtworks]]></category>

		<guid isPermaLink="false">http://www.shaunabram.com/?p=1953</guid>
		<description><![CDATA[ThoughtWorks Technology Radar is out and definitely worth a read. Although I follow many of the ThoughtWorks folks, like Martin Fowler, Neal Ford and Jez Humble, this is the first time I have read their tech radar, but it won&#8217;t be the last. The radar is basically the collective opinion of various ThoughtWorkers on the [...]]]></description>
				<content:encoded><![CDATA[<p>ThoughtWorks Technology Radar is <a href="http://www.thoughtworks.com/radar">out</a> and definitely worth a read. Although I follow many of the ThoughtWorks folks, like <a href="http://martinfowler.com/">Martin Fowler</a>, <a href="http://nealford.com/">Neal Ford</a> and <a href="http://jezhumble.net/">Jez Humble</a>, this is the first time I have read their tech radar, but it won&#8217;t be the last.</p>
<p><span id="more-1953"></span></p>
<p>The radar is basically the collective opinion of various ThoughtWorkers on the viability of a plethora of technology options, presumably gathered from the huge number of custom software projects they undertake each year. I found it very interesting and even started to read through a few of their older ones too.</p>
<p>They basically rate things on a 4 star scale:</p>
<ul>
<li>Adopt: Strongly recommend</li>
<li>Trial: Worth pursuing</li>
<li>Assess: Worth understanding</li>
<li>Hold: Proceed with caution</li>
</ul>
<p>Some of the things that jumped out at me from this years were:</p>
<h2>Techniques</h2>
<div dir="ltr" data-font-name="g_font_p8_4" data-canvas-width="31.011200672149656">
<ul>
<li>Development environments in the cloud get a thumbs up, tying in with my own +ve experiences of using GitHub for source control, a cloud based <a href="http://jenkins-ci.org/">Jenkins</a> to run tests and build, and deploying to <a href="http://www.cloudbees.com/">Cloudbees</a>. The teach radar explicitly mentions <a href="https://snap-ci.com/">Snap CI</a> (presumably tying in to <a href="https://www.heroku.com/">Heroku</a>). Perhaps somewhat biased as it is developed by ThoughtWorks, but still worth checking out I think.</li>
</ul>
</div>
<h2>Tools</h2>
<ul>
<li><a href="http://www.gradle.org/">Gradle</a> and <a href="http://en.wikipedia.org/wiki/Rake_%28software%29">Rake</a> both get a thumbs up (adopt) as build tools, while maven and ant continue to get a thumbs down (hold). I&#8217;ve been spending more time with Gradle recently, and am keen to move away from maven, so definitely agree.</li>
<li><a href="http://en.wikipedia.org/wiki/Splunk">Splunk</a> is a data index/search tool, e.g. for log files, that I have been using a lot recently and it continues to impress me. Although not mentioned in this issue of the radar, it has been favorably mentioned in past issues. It&#8217;s free version is more than feature rich enough for small to medium projects.</li>
<li><a href="http://d3js.org/">D3</a>: Data-Driven Documents. This is something that hasn&#8217;t been on my radar at all, but by the sounds of things, should be. It is an open source JavaScript library for displaying data in graphical form.</li>
</ul>
<h2>Platforms</h2>
<ul>
<li>MongoDB gets a a thumbs up (adopt), Hadoop (2.0) gets a &#8216;trial&#8217;.</li>
<li>AWS wasn&#8217;t explicitly mentioned, but has be been given an Adopt rating in the past, and I think is still what underpins many of the popular PAAS offerings out there.</li>
</ul>
<h2>Languages &amp; Frameworks</h2>
<ul>
<li>Scala and Clojure both get a thumbs up (adopt). I&#8217;m not too surprised by this as I have heard several ThoughtWorkers evangelize them in the past, and I am keen to continue playing with both more.</li>
<li>Java has been flagged as &#8216;assess&#8217; in previous editions and is not explicitly rated in the more recent one. It certainly seems to be increasingly viewed as a legacy technology. Still, I use it every day!</li>
<li>HTML5 continues to get favorable reviews. For example HTML5 storage gets a &#8216;Trial&#8217; rating.</li>
<li>JavaScript frameworks
<ul>
<li>Interestingly, <a href="http://nodejs.org/">Node.js</a> (server side JavaScript, using event driven async IO) gets a trial, but Node.js  with <a href="http://pivotal.github.io/jasmine/">Jasmine</a> (a BDD framework for testing JavaScript) gets a more positive thumbs up (adopt). I personally have been sceptical of Node.js. JavaScript on the server side sounds&#8230; weird, and I&#8217;ve heard that it can result in call-back hell, but I guess I need to reconsider!</li>
<li>The other JavaScript frameworks that seems to be viewed favorable were <a href="http://angularjs.org/">AngularJS </a>(an open-source JavaScript framework from Google) with <a href="http://knockoutjs.com/">Knockout</a> (JavaScript implementation of the Model-View-<wbr />ViewModel pattern), and <a href="http://requirejs.org/">Require.js</a> (a file and module loader for JavaScript). <a href="http://coffeescript.org/">CoffeeScript</a> (which compiles in to JavaScript) is also mentioned as one that continues to evolve well. Backbone.js gets a big old no (hold).</li>
</ul>
</li>
<li>Perhaps most interestingly of all to me was that component based frameworks (which, I think, in the Java world includes JSF, Wicket and Tapestry) get a big, unequivocal thumbs down (hold). GWT has also in the past (see July 2011 radar) been singled out as something to avoid. Presumably Vaadin falls in to the same &#8216;hold&#8217; category. I&#8217;ve had limited exposure to these types of frameworks (I&#8217;ve worked more on the traditional request based ones, like Spring MVC), and it sounds like that is not a bad thing.</li>
</ul>
<p>Overall, a thought provoking and insightful read from ThoughtWorks.</p>
<p>For me personally, my tech radar for the next few months includes getting more familiar with REST, exploring more of the JavaScript frameworks, and also looking more at Ruby on Rails. Clojure and Scala as language choice, and Gradle as a build tool also continue to interest me.</p>
<p>Feels like a good time to be a technologist&#8230;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunabram.com/thoughtworks-tech-radar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Builder Pattern: Good for code, great for tests</title>
		<link>http://www.shaunabram.com/builder-pattern/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=builder-pattern</link>
		<comments>http://www.shaunabram.com/builder-pattern/#comments</comments>
		<pubDate>Sun, 26 May 2013 08:13:41 +0000</pubDate>
		<dc:creator>sabram</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[builder]]></category>
		<category><![CDATA[designpatterns]]></category>
		<category><![CDATA[unittesting]]></category>

		<guid isPermaLink="false">http://www.shaunabram.com/?p=1883</guid>
		<description><![CDATA[I&#8217;ve found the builder design pattern occasionally useful in code, but frequently useful in tests. This article is a quick summary of the pattern in general, followed by look at a working example of using it in tests. See the code in github. Background to the Builder pattern According to the GoF book, the builder [...]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve found the builder design pattern occasionally useful in code, but frequently useful in tests. This article is a quick summary of the pattern in general, followed by look at a working example of using it in tests. See the code in <a href="https://github.com/sabram/BuilderPattern">github</a>.<br />
<span id="more-1883"></span></p>
<h3>Background to the Builder pattern</h3>
<p>According to the <a href="http://en.wikipedia.org/wiki/Design_Patterns">GoF book</a>, the builder design pattern is used to &#8220;Separate the construction of a complex object from its representation so that the same construction process can create different representations&#8221;. Like most of the GoF book, that is an accurate if dull description. </p>
<p>Josh Bloch, in his <a href="http://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/0321356683">Effective Java</a> book, suggests a more interesting use for builders. The problem his approach was trying to solve is when a class has &#8220;more than a handful&#8221; of parameters that would normally be set via a constructor, and many of them may be optional. Typical solutions are</p>
<ul>
<li>A telescoping constructor pattern, in which you provide a constructor with only the required parameters, as well as additional constructors with variations of the optional parameters, culminating in a constructor with all the optional parameters.<br />
This works, but makes for a fairly messy solution that has a potentially large number of constructors to cover all permutations</li>
<li>A simpler constructor (e.g. for just the required parameters), backed up by setter methods for the optional parameters (the JavaBeans approach). However, this can leave an object in an inconsistent state during it construction and of course precludes immutability since fields can&#8217;t be made <code>final</code>.</li>
<li>Use a Builder. This is the approach recommended by Bloch. The client creates a builder (often using a parameter-less constructor), then calls setter like methods for the values of interest (the rest assume default values), before finally calling a build method.</li>
</ul>
<p>A few years back, I attended <a href="http://www.shaunabram.com/code-camp-building-better-tests-in-java/">a talk</a> in which <a href="http://jitterted.com/">Ted Young</a> discussed taking the builder pattern a step further by using it for the construction of test objects, and it&#8217;s this approach that is discussed below.<br />
[Update: see Ted's response to this post <a href="http://jitterted.com/tidbits/2013/05/29/builders-for-testing/">here</a>]</p>
<h3>Using the Builder pattern to construct test fixtures</h3>
<p>Using a Builder allows test fixtures to be created more easily, and with clearer intent.</p>
<p>The type of test objects I typically use this Builder approach for are domain model objects, such as Account, User, Widget or whatever. I am a proponent of making such objects <a href="http://www.shaunabram.com/immutability/">immutable</a>.<br />
For example:</p>
<pre><code>public final class Account {
    private final Integer id;
    private final String name;
    private final AccountType type;
    private final BigDecimal balance;
    private final DateTime openDate;
    private final Status status;

    public Account(Integer id, String name, AccountType type,
                   BigDecimal balance, DateTime openDate, Status status) {
        this.id = id;
        this.name = name;
        this.type = type;
        this.balance = balance;
        this.openDate = openDate;
        this.status = status;
    }

    public Integer getId() {
        return id;
    }    

    //other getters, toString(), equals() and hashCode() omitted for brevity

    //no setters
}</code></pre>
<p>With such a class, you often run into the problem Bloch discussed. In this example, we have a single constructor that forces you to set all values, but we could also have many variations where some values can be omitted to use default values.<br />
So, creating an instance of such a class for tests can be somewhat painful, and more so if it has even more fields than this simple example. You are forced to provide values even for fields you may not care about for the test. That also makes it difficult to know which values are actually of interest for the test, and which are purely to make things compile.</p>
<p>A Builder can help.</p>
<h3>Example</h3>
<pre><code>public class AccountBuilder {

    //account fields with default values
    Integer id = 1;
    String name = "default account name";
    AccountType type = AccountType.CHECKING;
    BigDecimal balance = new BigDecimal(0);
    DateTime openDate = new DateTime(2013, 01, 01, 0, 0, 0);
    Status status = Status.ACTIVE;

    public AccountBuilder() {}

    public AccountBuilder withId(Integer id) {
        this.id = id;
        return this;
    }

    public AccountBuilder withName(String name) {
        this.name = name;
        return this;
    }

    public AccountBuilder withType(AccountType type) {
        this.type = type;
        return this;
    }

    public AccountBuilder withBalance(BigDecimal balance) {
        this.balance = balance;
        return this;
    }

    public AccountBuilder withOpenDate(DateTime openDate) {
        this.openDate = openDate;
        return this;
    }

    public AccountBuilder withStatus(Status status) {
        this.status = status;
        return this;
    }

    public Account build() {
        return new Account(id, name, type, balance, openDate, status);
    }
}</code></pre>
<p>Now you can create an Account object for testing much more easily.</p>
<h3>Notes on using Builder for tests</h3>
<ul>
<li>Default values</li>
<p>The default values used in a builder are a convenience to avoid exceptions. If your test needs specific values for a test, it is best to explicitly set them, rather than rely on any defaults. It makes the intent of your test clearer, plus minimizes the risk of inadvertently breaking tests if you ever need to change defaults (e.g. due to changing business requirements).</p>
<li>Non-final fields</li>
<p>While the domain model class itself is immutable and hence has final fields. All fields in the Builder are, by design, non-final. Hence Builders are not thread-safe. So don&#8217;t reuse Builders; instead create a new instance for each test.</p>
<li>Method order should not be significant</li>
<p>For the most part, the order that methods are called on a builder should not be significant, and the object will not be constructed until build() is called. This makes the builder easier to use and avoids unexpected surprises.<br />
There are obvious and acceptable exceptions to this rule of thumb.<br />
For example calling</p>
<pre><code>Account account = new AccountBuilder()
            .withType(AccountType.SAVING)
            .withType(AccountType.CHECKING)
            .build();</code></pre>
<p>is silly but allowed. It would just leave you with an account of type checking.<br />
This is fine, but try to avoid more subtle causes of confusion, for example if you have a collection that can have something added, or the whole collection replaced (hence wiping out previous additions).
</ul>
<h3>Advantages of using a Builder for tests</h3>
<ul>
<li>Easy to read</li>
<p>The following declaration is not particularly clear:</p>
<pre><code>    Account account = new Account(1, "test", 10, ...);</code></pre>
<p>This declaration is much clearer:</p>
<pre><code>Account account = new AccountBuilder()
                .withId(1)
                .withName("test")
                .withBalance(10)
                .build();</code></pre>
<p>As Bloch puts it, &#8220;The Builder pattern simulates named optional parameters&#8221;.</p>
<li>Only specify values that are actually relevant to your test</li>
<p>If your test is only concerned with account balance and status:</p>
<pre><code>        Account account = new AccountBuilder()
                .withBalance(new BigDecimal(-100))
                .withStatus(Status.OVERDRAWN)
                .build();</code></pre>
<p>As opposed to having to specify every value in the Accounts constructor.</p>
<li>Ability to create invalid objects</li>
<p>The constructor of the domain model class will likely (hopefully!) force you to create valid objects. In your tests, you may want to deliberately create invalid objects for testing.
</ul>
<h3>Further enhancements</h3>
<h4>Convenience methods</h4>
<p>You can add convenience methods for common scenarios used in testing.<br />
For example</p>
<pre><code>    public AccountBuilder withNegativeBalance() {
        this.balance = new BigDecimal(-100);
        return this;
    }</code></pre>
<h4>Fixtures class</h4>
<p>In addition to using a Builder class, I have also found it useful to have an associated fixtures class that provides pre-constructed instances for tests. These can make use of the Builder object for the construction (although there is nothing to stop you using the raw constructors too).<br />
For example</p>
<pre><code>public class AccountFixtures {

    //a shortcut to creating a basic Account object
    public final Account ACCOUNT = new AccountBuilder().build();

    public final Account OVERDRAWN_CHECKING_ACCOUNT = new AccountBuilder()
            .withType(AccountType.CHECKING)
            .withNegativeBalance()
            .build();

    public final Account CLOSED_SAVING_ACCOUNT = new AccountBuilder()
            .withType(AccountType.SAVING)
            .withZeroBalance()
            .withStatus(Status.CLOSED)
            .build();
}</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunabram.com/builder-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Immutability</title>
		<link>http://www.shaunabram.com/immutability/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=immutability</link>
		<comments>http://www.shaunabram.com/immutability/#comments</comments>
		<pubDate>Sun, 26 May 2013 07:46:48 +0000</pubDate>
		<dc:creator>sabram</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[effectivejava]]></category>
		<category><![CDATA[immutable]]></category>

		<guid isPermaLink="false">http://www.shaunabram.com/?p=1931</guid>
		<description><![CDATA[Immutable classes are inherently thread safe, and can only ever be in a single state. A class can be made immutable by: all fields being final and private no mutator (setter) methods class can&#8217;t be extended (e.g. make final) to avoid subclasses making things mutable provide exclusive access to any mutable components (e.g. getters provide [...]]]></description>
				<content:encoded><![CDATA[<p>Immutable classes are inherently thread safe, and can only ever be in a single state. A class can be made immutable by: </p>
<ul>
<li>all fields being final and private </li>
<li>no mutator (setter) methods</li>
<li>class can&#8217;t be extended (e.g. make final) to avoid subclasses making things mutable
</li>
<li>provide exclusive access to any mutable components (e.g. getters provide defensive copies of collections)</li>
</ul>
<p>See Item 15:Minimize mutability in <a href="http://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/0321356683">Effective Java</a> for more details.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunabram.com/immutability/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Maven archetypes to create your project folder structure</title>
		<link>http://www.shaunabram.com/maven-quickstart/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=maven-quickstart</link>
		<comments>http://www.shaunabram.com/maven-quickstart/#comments</comments>
		<pubDate>Sat, 18 May 2013 06:27:01 +0000</pubDate>
		<dc:creator>sabram</dc:creator>
				<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[devops]]></category>
		<category><![CDATA[gradle]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[mvn]]></category>

		<guid isPermaLink="false">http://www.shaunabram.com/?p=1886</guid>
		<description><![CDATA[Although gradle is my preferred build tool these days, the maven archetypes are still useful for creating a folder structure to start with. The easiest way to create a maven project structure is to use the quickstart archetype. For example: mvn archetype:generate -DgroupId=com.shaunabram -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false This creates my-app &#124;-- pom.xml `-- src &#124;-- main [...]]]></description>
				<content:encoded><![CDATA[<p>Although <a href="http://www.gradle.org/">gradle</a> is my preferred build tool these days, the <a href="http://maven.apache.org/">maven</a> <a href="http://maven.apache.org/archetype/maven-archetype-bundles/index.html">archetypes</a> are still useful for creating a folder structure to start with.<br />
<span id="more-1886"></span><br />
The easiest way to create a maven project structure is to use the <a href="http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html">quickstart</a> archetype. For example:</p>
<blockquote><p><code>mvn archetype:generate -DgroupId=com.shaunabram -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false</code></p></blockquote>
<p>This creates </p>
<pre>
my-app
|-- pom.xml
`-- src
    |-- main
    |   `-- java
    |       `-- com
    |           `-- shaunabram
    `-- test
        `-- java
            `-- com
                `-- shaunabram
                    `-- AppTest.java
</pre>
<p>Note this doesn&#8217;t create the (src/main/) resources folder. <a href="http://stackoverflow.com/questions/12634890/maven-archetype-quickstart-with-resources-folder">This</a> posting suggests creating your own custom archetype. Creating the folder manually isn&#8217;t too big a deal though.</p>
<p>If you&#8217;re creating a web app, a better alternative to the quickstart archetype is to use the <a href="http://maven.apache.org/archetype/maven-archetype-bundles/maven-archetype-webapp/">webapp</a> archectype.</p>
<blockquote><p><code>mvn archetype:generate -DgroupId=com.shaunabram -DartifactId=my-webapp -DarchetypeArtifactId=maven-archetype-webapp</code></p></blockquote>
<p>This creates </p>
<pre>my-webapp
   |-src
   |---main
   |-----resources
   |-----webapp
   |-------index.jsp
   |-------WEB-INF
   |---------web.xml
   |-pom.xml
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunabram.com/maven-quickstart/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Software Quality via Unit Testing</title>
		<link>http://www.shaunabram.com/dcc13/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=dcc13</link>
		<comments>http://www.shaunabram.com/dcc13/#comments</comments>
		<pubDate>Tue, 16 Apr 2013 05:39:27 +0000</pubDate>
		<dc:creator>sabram</dc:creator>
				<category><![CDATA[Testing]]></category>
		<category><![CDATA[cleancode]]></category>
		<category><![CDATA[codecamp]]></category>
		<category><![CDATA[dcc13]]></category>
		<category><![CDATA[desertcodecamp]]></category>
		<category><![CDATA[JUnit]]></category>
		<category><![CDATA[martinfowler]]></category>
		<category><![CDATA[talks]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[unittesting]]></category>

		<guid isPermaLink="false">http://www.shaunabram.com/?p=1829</guid>
		<description><![CDATA[The following post is based on a talk I gave at Desert Code Camp 2013. See also the associated slide deck. Software quality is critical to consistently and continually delivering new features to our users. This articles covers the importance of software quality and how to deliver it via unit testing, Test Driven Development and [...]]]></description>
				<content:encoded><![CDATA[<p>The following post is based on <a href="http://apr2013.desertcodecamp.com/session/672">a talk</a> I gave at <a href="http://http://apr2013.desertcodecamp.com/about">Desert Code Camp 2013</a>. See also the associated <a href="http://www.slideshare.net/shaunabram/dcc13">slide deck</a>.</p>
<p>Software quality is critical to consistently and continually delivering new features to our users. This articles covers the importance of software quality and how to deliver it via unit testing, Test Driven Development and clean code in general.<br />
<span id="more-1829"></span></p>
<h3>Introduction</h3>
<p>Unit testing has raised the quality of my code more than any other technique, approach or tool I have come across in the last 15 years. It helps you to write cleaner code, more quickly and with less bugs. It is also just feels good to write unit tests. That green bar in JUnit (or whatever testing tool you are using), gives you a warm fuzzy feeling. So, the bulk of this talk/article is about unit testing, and it’s smarter cousin, TDD.</p>
<p>&nbsp;</p>
<p>There are however, many other steps you can take, outside of unit testing, to improve the quality of code; Simple things such as:<br />
• good variable names<br />
• short cohesive methods that are easy to understand at a glance<br />
• avoiding code smells such as long nested if else if blocks<br />
So, the final section of my talk will be on what some people call ‘Clean Code’.</p>
<p>&nbsp;</p>
<p>But we&#8217;ll start by talking about why all this is important.<br />
After all, design, clean code and unit tests are merely an means to an end.<br />
And that end is: <strong>delivering value to users</strong><br />
And we should never forget that fact!</p>
<p>It is very important to be able to explain to project stakeholders, or indeed other developers, what the motivations and advantages are of unit testing and clean code, and how it ultimately results in value to users. And so, that is the basis for the introductory section called &#8216;The value of software design&#8217;.</p>
<ol>
<li>The value of software design</li>
<li>Automated testing</li>
<li>Clean code</li>
</ol>
<h3>1. The value of software design</h3>
<p>This section is largely based on <a href="http://www.youtube.com/watch?v=8kotnF6hfd8">a talk</a> (key part starts around 45:00; see also the <a href="http://martinfowler.com/bliki/DesignStaminaHypothesis.html">paper)</a> I was fortunate enough to attend by a guy called <a href="http://martinfowler.com/">Martin Fowler</a>, the &#8216;Chief Scientist&#8217; at a company called ThoughtWorks.<br />
In the talk, Fowler did a great job of answering a question I had been thinking about a lot: Why should we care about ‘good’ design in software?</p>
<p>People may put forward questions and statements such as</p>
<ul>
<li>We need less focus on quality so we can add more features</li>
<li>Do we really need unit tests?</li>
<li>Refactoring doesn’t change what the code does, so why bother?</li>
</ul>
<p>And it can be difficult to answer those questions, particularly when you are under pressure to deliver, and quickly.</p>
<p>On approach is to take the high moral ground.</p>
<p>For example, there are people who adopt the attitude that</p>
<ol>
<li>Bad software design is a sin</li>
<li>If you are not writing unit tests, with 100% unit test code coverage, you are a BAD developer</li>
<li>Poorly named variables or methods will be branded on your flesh as you burn in the fiery pits of hell for your sins</li>
</ol>
<p>Basically,  treat the issue as a moral one – you are a bad person (or at least a bad developer) if you are designing poor quality software.</p>
<p>However, most of us work for a living, and if we are going to take the time and effort to produce quality software, we need to have an <i>economic</i> reason for doing it – otherwise, why bother? If the software we are writing is not least providing significant benefit to our users and stakeholders, we probably shouldn’t be doing it.</p>
<p>Remember our goal: Deliver value to users</p>
<p>&nbsp;</p>
<h4>What does Quality even mean?</h4>
<p>But before we get into what economic reasons for good software design are, let’s talk about what Quality even means when it comes to software?</p>
<p>Well, it could mean a few different things, including:</p>
<ul>
<li>Quality GUI (easy to use, looks good, intuitive)</li>
<li>Few defects (bug free, no unintelligible error messages</li>
<li>Good modular design</li>
</ul>
<p>However, only the top two are actually apparent to users/customers/business sponsors. And yet this talk/article focuses almost exclusively on the last one – the one that users have no concept of!</p>
<p>And it’s not just users; Does your manager stay awake at night worrying about the quality of the code that you’re producing? Probably not. I bet your manager’s manager definitely doesn’t! And your CEO probably doesn’t even know what code is.</p>
<p>So if management and users don’t care about quality code, why should we, as developers care?</p>
<h4>Fowler&#8217;s Design Stamina Hypothesis</h4>
<p>Well Martin Fowler did a good job of describing why using what he calls the Design Stamina Hypothesis.</p>
<p><a href="http://www.shaunabram.com/wp-content/uploads/2013/04/DesignStaminaHypothesis.jpg"><img class="alignnone size-medium wp-image-1839" alt="DesignStaminaHypothesis" src="http://www.shaunabram.com/wp-content/uploads/2013/04/DesignStaminaHypothesis-300x161.jpg" width="550" height="295" /></a></p>
<ul>
<li>The y axis represents how much new functionality you are adding to the app</li>
<li>The x axis represents time</li>
<li>The orange line represents a hypothetical scenario where you create an app with no design (and design definitely includes unit tests)</li>
<li>The blue line represents a scenario where you create an app with good design</li>
</ul>
<p>&nbsp;</p>
<h5>Without design</h5>
<p>Fowler’s Design Stamina Hypothesis basically says that if you write code without a good design, you will be able to deliver code very quickly to start with, but your progress will become slower and slower over time and it becomes more and more difficult to add new features as you become bogged down</p>
<ul>
<li>in spaghetti code</li>
<li>fixing bugs introduced when you inadvertently broke an piece of code you couldn’t understand</li>
<li>spending hours trying to understand code before actually being able to change it (and still have little confidence that you’re not messing it up)</li>
</ul>
<p>In the worst case sceanario (shown above by the blue line tapering off), it will become so slow to make changes that you will likely start to consider a complete rewrite of the application. Because rewriting the entire thing, and the months/years of effort and blood/sweat/tears that that will take is actually more attractive that dealing with the mess you have created.</p>
<p>So, how do we avoid that worst case scenario, and what economic benefits can we reap?</p>
<h5>With good design</h5>
<p>Well, the second part of Fowler’s Design Stamina Hypothesis is how cumulative functionality is affected by good design. Designing, writing tests, using TDD may take a little longer in the short term, but the benefit is that in the medium to longer term [the point on the graph at which the lines cross), it actually makes you <i>much </i>faster.</p>
<ul>
<li>Adding new features takes about as long as you’d expect it to</li>
<li>Ever junior developers, or new team members, can add new features in a reasonable amount of time</li>
</ul>
<p>And in many cases that point is after days or weeks rather than months or years.</p>
<h5>Design Stamina Hypothesis summary</h5>
<p>In agile software development, the term often used to describe the amount of new functionality added over a period of time is velocity. Fowler&#8217;s notion on good design increasing velocity is just an hypothesis because it can’t be (easily) proved, but it intuitively makes sense to most people involved in producing software.</p>
<p>Design Stamina Hypothesis: Design is what gives us the stamina to be able to continually add new features to an application, today, tomorrow and for months and years to come.</p>
<p>&nbsp;</p>
<h4>Technical debt</h4>
<p>Basically what Fowler is talking about here is the concept of <a href="http://martinfowler.com/bliki/TechnicalDebt.html">technical debt</a>. Technical debt is a metaphor referring to the eventual consequences of poor design in a codebase. The debt can be thought of as extra work that needs to be done before or in addition to the <i>real</i> work that you need to do. For example, having to improve a design before you can actually add the new feature users have requested.</p>
<p>Under the technical debt metaphor, that extra work can be thought of as interest payments.</p>
<p><a href="http://www.shaunabram.com/wp-content/uploads/2013/04/TechDebtCost.png"><img class="alignnone size-medium wp-image-1853" style="width: 528px; height: 274px;" alt="TechDebtCost" src="http://www.shaunabram.com/wp-content/uploads/2013/04/TechDebtCost-300x161.png" width="700" height="287" /></a></p>
<p>Interest payments can come in the form of</p>
<ol start="1">
<li>Bugs</li>
<li>Just understanding what the heck the current code does</li>
<li>Refactoring</li>
<li>Completing unfinished work</li>
</ol>
<h5>How to deal with technical debt</h5>
<p>When you encounter technical debt in a project, you basically have 2 options open to you: Pay down or accept.<br />
Paying down the debt involves spending extra time to clean, refactor and improve design.<br />
The benefit is that it will ultimately speed you up since you&#8217;ll be able to add new features faster. The downside is that it will inevitably slow you down now.</p>
<p>Accepting the debt means doing the minimum required to add/change features and moving on. The interest you will pay going forward is the additional cost you incur above and beyond adding new features; Everything is slowed down and complicated by the extra complexity. In addition, it is also much more difficult for a new dev on the team to pick up. And last but by no means least, developer morale suffers! No developer enjoys working in an unmaintainable mess of code; And developer turnover is a very real cost.</p>
<p>So, when we come across code in our projects that is poorly designed, should we take action? Refactor, add tests, tidy up?</p>
<p>For a long time, I thought the answer to that question was simply Yes. Always. However, Fowler makes an excellent point that it is not always economically sensible to do so.</p>
<h6>If it ain’t broken, don’t fix it</h6>
<p>Even of a module is a bunch of crap; Badly written, with no tests and poor variable names etc;  If it</p>
<ul>
<li>(surprisingly) doesn’t have any bugs in it</li>
<li>does what it is supposed to</li>
<li>AND If you never need to change</li>
</ul>
<p>Then why worry about it? In technical debt terms, it is not exerting very many interest payments.</p>
<h6>Don’t build bad on top of bad</h6>
<p>On the other hand, if that badly written code needs to be updated with functionality, or if you find yourself ‘in it’ all the time (even just to understand it), then it becomes important to pay down technical debt and to keep the code clean and easy to maintain &amp; enhance</p>
<h4>Summary of the value of software design</h4>
<p>Good Design, tests and good coding practices  etc, are only a means to an end and that end is delivering value users. However, they are very useful in meeting that end. They give us the stamina to continually and consistently deliver functionality faster, with less bugs to our users and so have very real economic benefits</p>
<p>&nbsp;</p>
<p>And with that, let’s look at what it means to actually use good design techniques via the use of automated tests for software…</p>
<p>&nbsp;</p>
<h3>2. Automated testing</h3>
<h4>Unit testing</h4>
<p>A unit test is a piece of code that executes a specific functionality (‘unit’) in the code, and</p>
<ul>
<li>Confirms the behavior or result is as expected.</li>
<li>Determines if code is ‘fit for use’</li>
</ul>
<h5>Unit testing example</h5>
<div>It is easiest to explain via an example. This example involves testing a factorial routine. The factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example, the factorial of 3 is equal to 6: 3! = 3 x 2 x 1 = 6</div>
<div>Our implementation of this is as follows:public class Math {</div>
<pre>    public int factorial(int n) {</pre>
<pre>        if (n == 1) return 1;</pre>
<pre>        return n * factorial(n-1);</pre>
<pre>    }</pre>
<pre>}</pre>
<p>And being good developers, we add a test to make sure the code does what we expect:</p>
<pre>public class MathTest {</pre>
<pre>    @Test</pre>
<pre>    public void factorial_positive_integer() {</pre>
<pre>        Math math = new Math();</pre>
<pre>        int result = math.factorial(3);</pre>
<pre>        assertThat(result).isEqualTo(6);</pre>
<pre>    }</pre>
<pre>}</pre>
<p>And if we run the test, we will see it passes. Our code must be correct?</p>
<p>Well one good thing about tests is that they make you start to think about edge cases. Anobvious one here is zero. So we add a test for that. In mathematics, the factorial of zero is 1 (0! = 1), so we add a test for that:</p>
<pre>public class MathTest {</pre>
<pre>…</pre>
<pre>    @Test</pre>
<pre>    public void factorial_zero() {</pre>
<pre>        Math math = new Math();</pre>
<pre>        int result = math.factorial(0);</pre>
<pre>        assertThat(result).isEqualTo(1);</pre>
<pre>    }</pre>
<pre>}</pre>
<p>And when we run this test&#8230; we see that it fails. Specifically, it will result in some kind of stack overflow. We have found a bug!</p>
<p>The issue is our exit condition, or the first line in our algorithm:</p>
<p>if (n == 1) return 1;</p>
<p>This needs to be updated to check for zero:</p>
<p>if (n == 0) return 1;</p>
<p>With our algorithm updated, we re-run our tests and all pass. Order is restored to the universe!</p>
<h5>What unit tests provide</h5>
<p>Although our previous example demonstrated unit tests finding a bug, find bugs isn&#8217;t the unit tests primary benefit. Instead, unit tests:</p>
<ul>
<li>Drive design</li>
<li>Act as safety buffers by finding regression bugs</li>
<li>Provide documentation</li>
</ul>
<h6>Drive design</h6>
<p>TDD can help drive design and tease the requirements out. The tests effectively act as the first user of the code, making you think about:</p>
<ul>
<li>what <i>should</i> this code do</li>
<li>Border conditions (0, null, -ve, too big)</li>
</ul>
<p>They can also push you to use good design, such as</p>
<ul>
<li>Short methods
<ul>
<li>difficult to unit test a methid that is 100 lines long, so unit esting forces you to write modular code (low coupling, high cohesion;</li>
<li>Test names can highlight violations of SRP; if you start writing a test name like addTwoNumbers_sets_customerID correctly, you are probably doing something very wrong</li>
</ul>
</li>
<li>Dependency Injection</li>
</ul>
<p>Basically, writing a class is different from using a class and you need to be aware of that as you write code.</p>
<h6>Act as safety buffers by finding regression bugs</h6>
<p>Have you ever been in a bowling alley and seen those buffers or bumpers they put down the side of each lane for beginners or kids, to stop the ball running out? Well unit tests are kind of like that. They act as a safety net by allowing code to be refactored without fear of breaking existing functionality.</p>
<p>Having a high test coverage of your code allows you to continue developing features without having to perform lots of manual tests.  When a change introduces a fault, it can be quickly identified and fixed.</p>
<p>Regression testing (checking existing functionality to ensure it hasn&#8217;t been broken by later modifications to the code) is one of the biggest benefits to Unit Testing &#8211; especially when you&#8217;re working on a large project where developers don&#8217;t know the ins and outs of every piece of code and hence are likely to introduce bugs by incorrectly working with code written by other developers.</p>
<p>Unit tests are run frequently as the code base is developed, either as the code is changed or via an automated process with the build. If any of the unit tests fail, it is considered to be a bug either in the changed code or the tests themselves.</p>
<h6>Documentation</h6>
<p>Another benefit of unit testing is that it provides a form of living documentation about how the code operates. Unit test cases embody characteristics that are critical to the success of the unit. The test method names provide a succinct description of what a class does.</p>
<h5>Unit testing limitations</h5>
<p>Unit testing of course has its limitations:</p>
<ul>
<li>Can not prove the absence of bugs</li>
</ul>
<p>While unit tests can prove the presence of bugs, they can never prove their absence (They can prove the absence of specific bugs, yes, but not all bugs). For example, unit tests test what you tell them too. If you don’t think of an edge case, you probably aren’t going to write either a test of the functionality to handle it! For reasons like this, unit tests should augment, never replace, manual testing.</p>
<ul>
<li>Lot’s of code (x3-5)</li>
</ul>
<p>In the simple unit test example we saw earlier, the unit tests had about 3 times the amount of code as the actual code under test &#8211; and there were still other scenarios we hadn&#8217;t tested yet. In general, for every line of code written, programmers often need 3 to 5 lines of test code. For example, every boolean decision statement requires at least two tests. Test code quickly builds up and it all takes time to write, read and maintain, and run.</p>
<ul>
<li>Some things difficult to test</li>
</ul>
<p>Some things are extremely difficult to test e.g. threading, GUI.</p>
<ul>
<li>Testing legacy code bases can be challenging</li>
</ul>
<p>A common approach to adding unit testing to existing code is to start with one wrapper test, then simultaneously refactor and add tests as you go along. For example if you have a legacy method that has 200 lines of code, you might start by adding one test that, for a given set of parameters gives you a certain return value. This will not test all the side effects the method has (e.g. the effect of calls to other objects), but it is a starting point. You can then start refactoring the method down into smaller methods, adding unit tests as you do so. The initial &#8216;wrapper&#8217; test will give you some degree of confidence that you have not fundamentally broken the original functionality and the new incremental tests you add as you go about refactoring will give you increased confidence, as well as allowing you to understand (and document) the code.</p>
<p>It is worth pointing out though that in some cases, the setup for objects not originally designed with unit testing in mind can be more trouble than it is worth. In these cases, you need to make the kind of decisions we discuss earlier in the technical debt section.</p>
<p>So, given all those limitations, should we unit test? Absolutely! In fact, not only should we unit test, we should let unit tests drive development and design, via Test Driven Development (TDD).</p>
<h4>Test driven development</h4>
<h5>TDD Intro</h5>
<p>Test-driven development is a set of techniques which encourages simple designs and test suites that inspire confidence.</p>
<p>The classic approach to TDD is Red &#8211; Green &#8211; Refactor</p>
<ol>
<li>Red— Write a failing test, one that may not even compile at first</li>
<li>Green— Make the test pass quickly, committing whatever sins necessary in the process</li>
<li>Refactor— Eliminate all of the duplication created in merely getting the test to work</li>
</ol>
<p style="text-align: center;"><a href="http://www.shaunabram.com/wp-content/uploads/2013/04/TDD.jpg"><img class="size-medium wp-image-1856 aligncenter" alt="TDD" src="http://www.shaunabram.com/wp-content/uploads/2013/04/TDD-300x198.jpg" width="300" height="198" /></a></p>
<p>Red- green/refactor—the TDD mantra.</p>
<p>No new functionality without a failing test; no refactoring without passing tests.</p>
<h5>TDD Example</h5>
<p>As with straight unit testing, TDD is best explained via an example. However, this section is best viewed as code screen shots. See the presentation slides <a href="http://www.slideshare.net/shaunabram/dcc13/35">here</a>.</p>
<p>A few points are worth noting from the TDD example:</p>
<ul>
<li>Writing the tests resulted in code that is clean and easy to understand; likely more so than if we had added tests after the fact (or not at all)</li>
<li>The test names act as a good form of documentation</li>
<li>Finally, there is about five times more test code than the code we were testing, as we predicted earlier. This emphasizes why it is so important to refactor the test code just as, it not more, aggressively than the actual code under test.</li>
</ul>
<p>&nbsp;</p>
<p>So far we have looked why we should be concerned with good design in the first place, and how we can use automated tests to drive and confirm our design.</p>
<p>Next, we are going to talk about how to spot issues with an existing code base by looking for code smells…</p>
<p>&nbsp;</p>
<h3>3. Clean code</h3>
<p>One way to ensure clean code is by avoiding &#8216;code smells&#8217;.</p>
<p>What is a code smell?</p>
<p>“Certain structures in code that suggest (sometimes they scream for) the possibility of refactoring.” Martin Fowler. <a href="http://martinfowler.com/books/refactoring.html">Refactoring: Improving the design of existing code</a></p>
<p>A &#8216;smell&#8217; in code is a hint that something might be wrong with the code. To quote the Portland Pattern Repository&#8217;s Wiki, if something smells, it definitely needs to be checked out, but it may not actually need fixing or might have to just be tolerated. The code that smells may itself need fixing, or it may be a symptom of, or hiding, another issue. Either way, it is worth looking into.</p>
<p>We will look at the following code smells:</p>
<div>•Duplicated code</div>
<div>•Long switch/if statements</div>
<div>•Long methods</div>
<div>•Poor method names</div>
<div>•In-line comments</div>
<div>•Large classes</div>
<div></div>
<div>
<h4>Duplicated code</h4>
<p>This is the #1 stink! It violates the <a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself">DRY principle</a>.</p>
<p>If you see the same code structure in more than one place, you can be sure that your program will be better if you find a way to unify them.</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="221">Symptom</td>
<td valign="top" width="221">Possible actions</td>
</tr>
<tr>
<td valign="top" width="221">same expression in two methods of the same class</td>
<td valign="top" width="221">Extract to a new method</td>
</tr>
<tr>
<td valign="top" width="221">same expression in two sibling subclasses</td>
<td valign="top" width="221">Extract to a method in a parent class</td>
</tr>
<tr>
<td valign="top" width="221">same expression in two unrelated classes</td>
<td valign="top" width="221">Extract to a new class? Have one class invoke the other?</td>
</tr>
</tbody>
</table>
<p>In all cases, parametrize any subtle differences in the duplicated code.</p>
<h4>Long switch / if statements</h4>
<p>The problem here is also one duplication.</p>
<ul>
<li>The same switch statement is often duplicated in multiples places. If you add a new clause to the switch, you have to find all these switch, statements and change them.</li>
<li>Or similar code being done in each switch statement</li>
</ul>
<p>The solution is often to use use polymorphism. For example, if you are switching on a code of some kind, move the logic into the class that owns the codes, then introduce code specific subclasses. An alternative is to use the <a href="http://en.wikipedia.org/wiki/State_pattern">State</a> of <a href="http://en.wikipedia.org/wiki/Strategy_pattern">Strategy</a> design patterns.</p>
<h4>Long method</h4>
<p>The longer a method is, the more difficult it is to understand. Older languages carried an overhead in subroutine calls. Modern OO languages have virtually eliminated that overhead.</p>
<p>The key is good naming. If you have a good name for a method you don&#8217;t need to look at the body.</p>
<p>Methods should be short (&lt;10 line)</p>
<p>A one line method seems a little too short, but even this is OK if it adds clarity to the code.</p>
<p>Be aggressive about decomposing methods!</p>
<p>The real key to decomposing methods into shorter ones is avoiding poor method names…</p>
<p>&nbsp;</p>
<h4>Poor method names</h4>
<p>Method names should be descriptive, for example</p>
<ul>
<li>int process(int id) { //bad!</li>
<li>int calculateAccountBalance(int accountID) { //better</li>
</ul>
<p>&nbsp;</p>
<p>i.e. the method name should descibe what the method does without having to read the code</p>
<p>or at least, a quick scan of the code should confirm the method does what it says on the tin</p>
<p>&nbsp;</p>
<h4>In-line comments</h4>
<p>Yes, in-line comments can be considered a code smell! If the code is so difficult to follow that you need to add comments to describe it, consider refactoring!</p>
<p>The best ‘comments’ are simply the names you give you methods and variables.</p>
<p>Note however, that Javadocs, particularly on public methods, are fine and good.</p>
<h4>Large classes</h4>
<p>When a class is trying to do too much, it often shows up as:</p>
<ul>
<li>Too many methods (&gt;10 public?)</li>
<li>Too many lines of code</li>
<li>Too many instance variables – is every instance variable used in every method?</li>
</ul>
<p>Solutions</p>
<ul>
<li>Eliminate redundancy / duplicated code</li>
<li>Extract new/sub classes</li>
</ul>
<p>&nbsp;</p>
<h4>Clean code summary</h4>
<p>The single most important thing is to make the intent of your code clear.</p>
<p>Your code should be clear, concise and easy to understand because although a line of code is written just once, it is likely to be read many times.</p>
<p>Will you be able to understand your intent in a month or two? Will your colleague? Will a junior developer?</p>
<p>A software program will have, on average, 10 generations of maintenance programmers in its lifetime.</p>
<p>Maintaining such unreadable code is hard work because we expend so much energy into understanding what we’re looking at. It’s not just that, though. <a href="http://doi.ieeecomputersociety.org/10.1109/TSE.2009.70">Studies</a> have shown that poor readability correlates strongly with defect density. Code that’s difficult to read tends to be difficult to test, too, which leads to fewer tests being written.</p>
<h3>Summary</h3>
<div>•Good design gives us the stamina to continually and consistently deliver business value</div>
<div>•Unit tests are an integral part of good design; TDD is even better</div>
<div>•Good design can also simply be cleaner code; Aggressively refactor to achieve this</div>
<div></div>
<p>Final thought: Every time you are in a piece of code, just make one small improvement!</p>
<p>&nbsp;</p>
<p>Recommended reading:</p>
<ul>
<li><a href="http://martinfowler.com/books/refactoring.html">Refactoring: Improving the Design of Existing Code</a></li>
<li><a href="http://www.amazon.com/Test-Driven-Development-Kent-Beck/dp/0321146530">Test Driven Development: By Example</a></li>
<li><a href="http://www.growing-object-oriented-software.com/">Growing Object-Oriented Software Guided by Tests</a></li>
<li><a href="http://www.amazon.com/Effective-Unit-Testing-guide-Developers/dp/1935182579">Effective Unit Testing</a></li>
</ul>
</div>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunabram.com/dcc13/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cloudbees</title>
		<link>http://www.shaunabram.com/cloudbees/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=cloudbees</link>
		<comments>http://www.shaunabram.com/cloudbees/#comments</comments>
		<pubDate>Mon, 07 Jan 2013 00:02:41 +0000</pubDate>
		<dc:creator>sabram</dc:creator>
				<category><![CDATA[Products]]></category>
		<category><![CDATA[cloud]]></category>
		<category><![CDATA[cloudbees]]></category>
		<category><![CDATA[continuousdeployment]]></category>
		<category><![CDATA[continuousintegration]]></category>
		<category><![CDATA[jenkins]]></category>
		<category><![CDATA[Maven]]></category>

		<guid isPermaLink="false">http://www.shaunabram.com/?p=1780</guid>
		<description><![CDATA[I&#8217;ve been using CloudBees a lot recently for deploying to &#8216;the cloud&#8217;. There are a couple of things that attract me to CloudBees&#8230; Jenkins builds via DEV@cloud The first is the what CloudBees call DEV@cloud and what I simply think of as an online Jenkins instance. I am a big Jenkins fan (at home and [...]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve been using <a href="http://www.cloudbees.com/">CloudBees</a> a lot recently for deploying to &#8216;the cloud&#8217;.<br />
There are a couple of things that attract me to CloudBees&#8230;<br />
<span id="more-1780"></span></p>
<h3>Jenkins builds via DEV@cloud</h3>
<p>The first is the what CloudBees call DEV@cloud and what I simply think of as an online Jenkins instance. I am a big <a href="http://jenkins-ci.org/">Jenkins</a> fan (at home and work) and having a cloud based Jenkins instance is invaluable. The GitHub integration means I can check in code and have all tests run and a war file build automatically. I tend to use maven as the build tool for my projects, so with DEV@cloud&#8217;s &#8216;Poll SCM&#8217; turned on, all I have to do is check in a change, and it builds. Nice.</p>
<h3>Automatic deployment to the cloud via RUN@cloud</h3>
<p>The second cool thing about CloudBees (and the deal winner for me) is the automatic deployment option. When I check in a new piece of code, not only will CloudBees do a maven build for me, it will also deploy it to the cloud. And all it takes is clicking a single checkbox. Literally. They couldn&#8217;t possibly have made it any easier. By default, it will be given a URL such as yourappid.youruserid.cloudbees.net, but this is configurable. The cloud deployment is what CloudBees call RUN@Cloud</li>
<h3>And beyond&#8230;</h3>
<p>At a certain point of course, you need to start being more specific about how to deploy an app than just saying &#8216;deploy it&#8217;. That is when the <a href="https://wiki.cloudbees.com/bin/view/RUN/BeesSDK">Cloudbees SDK</a> comes into play. Download it and you can then start specifying details of the deployment such as a specific JVM/Java/JRE version, memory options, security, scalability etc.</p>
<p>So far, I&#8217;ve been using CloudBees for prototypes such as <a href="http://www.shaunabram.com/handsontable-springmvc-ajax/">this Handsontable / SpringMVC example</a>, a <a href="http://www.shaunabram.com/springmvc-file-download/">SpringMVC file download example</a>, a <a href="http://www.shaunabram.com/springmvc-continuous-deployment/">SpringMVC HelloWorld template</a> I use for bootstrapping projects, and a simple app for managing money called <a href="http://www.shaunabram.com/mymoney-springmvc-app/">MyMoney</a>. But everything I&#8217;ve seen suggests CloudBees as a viable solution for live, production cloud-based apps.</p>
<p>For the record, I have no relationship with CloudBees other than a happy user.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunabram.com/cloudbees/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Handsontable &#8216;Spreadsheet&#8217; talking to SpringMVC</title>
		<link>http://www.shaunabram.com/handsontable-springmvc-ajax/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=handsontable-springmvc-ajax</link>
		<comments>http://www.shaunabram.com/handsontable-springmvc-ajax/#comments</comments>
		<pubDate>Sun, 06 Jan 2013 07:39:44 +0000</pubDate>
		<dc:creator>sabram</dc:creator>
				<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[Products]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[handsontable]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[jsp]]></category>
		<category><![CDATA[spreadsheet]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[springmvc]]></category>

		<guid isPermaLink="false">http://www.shaunabram.com/?p=1766</guid>
		<description><![CDATA[Handsontable is an Excel-like data grid utilizing JQuery. For example, it provides the ability to copy and paste directly to &#038; from Excel. Handsontable itself if very easy to setup. The part I struggled with was passing the data to SpringMVC. So, this post shows how to send data from a Handsontable data grid on [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://handsontable.com">Handsontable</a> is an Excel-like data grid utilizing JQuery. For example, it provides the ability to copy and paste directly to &#038; from Excel. Handsontable itself if very easy to setup. The part I struggled with was passing the data to SpringMVC. So, this post shows how to send data from a Handsontable data grid on the client to a SpringMVC server. </p>
<p><span id="more-1766"></span></p>
<p>The code for the example is posted <a href="https://github.com/sabram/Handsontable-SpringMVC">here on GitHub</a> and has also been deployed <a href="http://handsontable-springmvc.shaunabram.cloudbees.net/">here on CloudBees</a>.</p>
<p>For this example, the server simply returns the data back to the client where it is displayed in a results section of the same JSP. The data is posted as JSON via a JQuery AJAX call. </p>
<p>The code follows the example posted in <a href="http://stackoverflow.com/questions/5908466/jquery-spring-mvc-requestbody-and-json-making-it-work-together/5908632#5908632">the accepted answer in this Stackoverflow question</a>.</p>
<p>In addition to the usual SpringMVC setup, the key parts are:</p>
<ul>
<li>Adding a maven pom dependency on Jackson, to handle the Json to Java conversion (automatically detected by SpringMVC)</li>
<li>Use the SpringMVC @ResponseBody and @RequestBody web binding annotations in your controller methods to ensure that Spring converts the Json to and from your java objects</li>
<li>Making sure the JQuery Ajax call includes the correct headers and data type, as in:
<pre><code>jQuery.ajax({
    type: "POST",
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
        },
    'dataType': 'json',
    ...
});</code></pre>
</li>
</ul>
<p>Again, the full code of the working example is posted <a href="https://github.com/sabram/Handsontable-SpringMVC">here on GitHub</a> and deployed <a href="http://handsontable-springmvc.shaunabram.cloudbees.net/">here on CloudBees</a>. I use continuous deployment by using a <a href="https://shaunabram.ci.cloudbees.com/job/Handsontable-SpringMVC/">Jenkins instance</a>, also on Cloudbees.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunabram.com/handsontable-springmvc-ajax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SpringMVC file download</title>
		<link>http://www.shaunabram.com/springmvc-file-download/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=springmvc-file-download</link>
		<comments>http://www.shaunabram.com/springmvc-file-download/#comments</comments>
		<pubDate>Thu, 13 Dec 2012 03:03:20 +0000</pubDate>
		<dc:creator>sabram</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[springmvc]]></category>

		<guid isPermaLink="false">http://www.shaunabram.com/?p=1750</guid>
		<description><![CDATA[This post shows how to download a file using Spring MVC. For example, you have a SpringMVC web app and you want to include a link on a page that downloads a file to be opened on the user&#8217;s machine (e.g. a Microsoft Excel). The code is as follows: @RequestMapping(value = "/Excel", method = RequestMethod.GET) [...]]]></description>
				<content:encoded><![CDATA[<p>This post shows how to download a file using Spring MVC. For example, you have a SpringMVC web app and you want to include a link on a page that downloads a file to be opened on the user&#8217;s machine (e.g. a Microsoft Excel).<br />
<span id="more-1750"></span><br />
The code is as follows:</p>
<pre><code>    @RequestMapping(value = "/Excel", method = RequestMethod.GET)
    public void handleFileDownload(HttpServletResponse res) {
        try {
            String fn = "/Test.xls";
            URL url = getClass().getResource(fn);
            File f = new File(url.toURI());
            System.out.println("Loading file "+fn+"("+f.getAbsolutePath()+")");
            if (f.exists()) {
                res.setContentType("application/xls");
                res.setContentLength(new Long(f.length()).intValue());
                res.setHeader("Content-Disposition", "attachment; filename=Test.xls");
                FileCopyUtils.copy(new FileInputStream(f), res.getOutputStream());
            } else {
                System.out.println("File"+fn+"("+f.getAbsolutePath()+") does not exist");
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }</code></pre>
<p>Where:</p>
<ul>
<li>&#8220;/Excel&#8221; is an arbitrary path name (can be anything)</li>
<li>&#8220;Test.xls&#8221; resides in src/main/resources</li>
</ul>
<p>The code uses Spring&#8217;s own FileCopyUtils for making the file available.<br />
The complete maven project can be found <a href="https://github.com/sabram/SpringMVC-FileDownload">here on github</a> and the deployed project can be found <a href="http://springmvc-filedownload.shaunabram.cloudbees.net/">here on cloudbees</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunabram.com/springmvc-file-download/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MyMoney &#8211; A simple SpringMVC app</title>
		<link>http://www.shaunabram.com/mymoney-springmvc-app/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mymoney-springmvc-app</link>
		<comments>http://www.shaunabram.com/mymoney-springmvc-app/#comments</comments>
		<pubDate>Tue, 16 Oct 2012 17:48:53 +0000</pubDate>
		<dc:creator>sabram</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[springmvc]]></category>

		<guid isPermaLink="false">http://www.shaunabram.com/?p=1712</guid>
		<description><![CDATA[I created a small, open source web app called MyMoney for entering and tracking spending details. It allows you to create accounts (for example Cash or Checking) and enter transactions associated with those accounts. The app is running at http://mymoney.shaunabram.cloudbees.net and the sourecode is available via GitHub. Similar to the simple HelloWorld SpringMVC app I [...]]]></description>
				<content:encoded><![CDATA[<p>I created a small, open source web app called <a href="http://mymoney.shaunabram.cloudbees.net">MyMoney</a> for entering and tracking spending details. It allows you to create accounts (for example Cash or Checking) and enter transactions associated with those accounts.</p>
<p>The app is running at <a href="http://mymoney.shaunabram.cloudbees.net">http://mymoney.shaunabram.cloudbees.net</a> and the sourecode is available via <a href="https://github.com/sabram/MyMoney">GitHub</a>.<br />
<span id="more-1712"></span></p>
<p>Similar to the simple <a href="http://www.shaunabram.com/springmvc-continuous-deployment/">HelloWorld SpringMVC</a> app I posted a while ago, I created this as a way to get more familiar with certain technologies, rather than as a serious app. It uses JSP/CSS on the front end, Java &#038; Spring MVC on the server with a MySQL database accessed via Hibernate (as well as the in-memory HSQLDB database for tests).</p>
<p>It also utilizes Continuous Deployment. Any new check-ins are automatically tested and built (using maven) and deployed using Jenkins and CloudBees.</p>
<p>There are a bunch of things I will do differently on the next pet project I undertake, such as using MyBatis instead of Hibernate (<a href="http://hallofthemountainking.wordpress.com/2011/11/11/now-why-am-i-so-much-in-love-with-mybatis/">this post</a> sums up my current feelings very well), utilizing Selenium and using Twitter Bootstrap instead of raw css, but for now, I am shelving this project in its current form and moving on.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunabram.com/mymoney-springmvc-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Certified ScrumMaster</title>
		<link>http://www.shaunabram.com/certified-scrummaster/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=certified-scrummaster</link>
		<comments>http://www.shaunabram.com/certified-scrummaster/#comments</comments>
		<pubDate>Wed, 03 Oct 2012 04:50:25 +0000</pubDate>
		<dc:creator>sabram</dc:creator>
				<category><![CDATA[Certification]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[scrum]]></category>

		<guid isPermaLink="false">http://www.shaunabram.com/?p=1707</guid>
		<description><![CDATA[I became a Certified ScrumMaster today via the Scrum Alliance. I know certifications are worth very little, but the training and exam prep was definitely very useful and, more importantly, I&#8217;m implementing Scrum techniques on the new project I&#8217;m working on: Planning the sprint ahead, daily scrums, sprint reviews and trying to remove obstacles for [...]]]></description>
				<content:encoded><![CDATA[<p>I became a <a href="http://www.shaunabram.com/?attachment_id=1706">Certified ScrumMaster</a> today via the <a href="http://scrumalliance.com/">Scrum Alliance</a>. I know certifications are worth very little, but the training and exam prep was definitely very useful and, more importantly, I&#8217;m implementing Scrum techniques on the new project I&#8217;m working on: Planning the sprint ahead, daily scrums, sprint reviews and trying to remove obstacles for the team.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunabram.com/certified-scrummaster/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
