<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>A View From Above: Category Programming</title>
    <link>http://www.ghostganz.com/blog/articles/category/programming</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Anders Bengtsson on programming and other things</description>
    <item>
      <title>The Things That Are Wrong With Maven</title>
      <description>&lt;p&gt;&lt;em&gt;Last week I attended a small workshop on building with Maven, which quickly turned into a Buildr workshop once we realized that most attending simply didn&amp;#8217;t like Maven very much. It inspired me to write down some of the things&lt;/em&gt; I &lt;em&gt;don&amp;#8217;t like with Maven:&lt;/em&gt;&lt;/p&gt;


	&lt;h3&gt;Verbosity&lt;/h3&gt;


	&lt;p&gt;Maybe the problem is spelled &amp;#8220;XML&amp;#8221;.&lt;/p&gt;


	&lt;p&gt;&lt;a href="http://incubator.apache.org/buildr/"&gt;Buildr&lt;/a&gt; shows that you can express essentially the same things as Maven&amp;#8217;s pom files in &lt;em&gt;an order of magnitude&lt;/em&gt; fewer lines and still be &lt;em&gt;more&lt;/em&gt; readable. Good old Ant has the excuse of being created in a time when &lt;span class="caps"&gt;XML&lt;/span&gt; was hyped, but there&amp;#8217;s no excuse for the masses of &lt;span class="caps"&gt;XML&lt;/span&gt; that Maven forces you to create and maintain.&lt;/p&gt;


	&lt;h3&gt;Working With Legacy Code&lt;/h3&gt;


	&lt;p&gt;Have you ever tried to introduce Maven to build a large legacy system? Because of Maven&amp;#8217;s inflexibility, you can&amp;#8217;t easily do this in small steps, incrementally moving closer to (Maven&amp;#8217;s idea of) an ideal file and dependency structure. Instead you&amp;#8217;re looking at doing it all in a single huge, messy, risky step.&lt;/p&gt;


	&lt;h3&gt;Transitive Dependencies&lt;/h3&gt;


	&lt;p&gt;Nice in theory. In practice this means Maven will download half the internet for you and at the same time making you sensitive to every minor slip-up in any pom of any n-level indirect dependency you have.
Even if your code never invokes the rarely used parts of commons-something that actually depends on commons-kitchen-sink, you&amp;#8217;re going to get commons-kitchen-sink. Or maintain the screenful of &lt;span class="caps"&gt;XML&lt;/span&gt; to override it.&lt;/p&gt;


	&lt;h3&gt;Flexibility and Plugins&lt;/h3&gt;


	&lt;p&gt;Most non-trivial projects have at least one detail that just doesn&amp;#8217;t fit Maven&amp;#8217;s model. In any other build tool that can be easily remedied with (often just a single line of) scripting. In Maven, the solution is &lt;em&gt;plugins&lt;/em&gt;.
So your build ends up depending on abandoned third-party plugins just to accomplish the most trivial scripting tasks. So much for dependency management.&lt;/p&gt;


	&lt;h3&gt;Unit Testing&lt;/h3&gt;


	&lt;p&gt;When unit testing, you are only interested in two things: Are my tests at 100% and, if not, what is failing? (And, for bragging rights, how many tests do I have?) Just like Ant before it, Maven fails badly at this.
The (mostly useless) stdout from the tested code is puked to the terminal, drowning Maven&amp;#8217;s own test summaries. The causes of failures, on the other hand, are hidden away in report files in some other directory.&lt;/p&gt;


	&lt;p&gt;I can see the use for &amp;#8220;test reports&amp;#8221; in some scenarios and tool sets, but as a default behavior for a &lt;em&gt;unit&lt;/em&gt; test runner they&amp;#8217;re absurd.&lt;/p&gt;


	&lt;h3&gt;Build Output&lt;/h3&gt;


	&lt;p&gt;Why is so much useless output written to the terminal during a build? Are they trying to impress Linux Kernel hackers?&lt;/p&gt;


	&lt;h3&gt;Repositories&lt;/h3&gt;


	&lt;p&gt;It&amp;#8217;s good practice to keep the things you depend on under version control, among other things for repeatability. Maven&amp;#8217;s take on this is to keep dependency meta-data under version control, and download the dependencies themselves from public repositories.
So now you&amp;#8217;re depending on someone else&amp;#8217;s public repository to be available (and correctly configured and maintained). If it&amp;#8217;s not, you won&amp;#8217;t be able to build on a freshly installed machine.
I&amp;#8217;m told the recommended solution is to have your own local caching repo (which also allows you to depend on private or proprietary libraries). So now you have yet another server to maintain. Wouldn&amp;#8217;t it be both less work and lower risk to just keep the jars under local version control?&lt;/p&gt;


	&lt;p&gt;(Also, the only caching repo I have tried, Artifactory, kept corrupting data. It was probably a problem with its embedded Jackrabbit content repository, but still).&lt;/p&gt;


	&lt;h3&gt;File Structure&lt;/h3&gt;


	&lt;p&gt;I&amp;#8217;m forced to structure my files in a way the Maven developers, a group whose judgement and taste I usually dissent with, find ideal.&lt;/p&gt;


	&lt;p&gt;I could go on all day&amp;#8230;&lt;/p&gt;</description>
      <pubDate>Sun, 26 Oct 2008 12:26:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:e14a89b3-214f-4e36-b5ae-a577a7467901</guid>
      <author>Anders</author>
      <link>http://www.ghostganz.com/blog/articles/2008/10/26/the-things-that-are-wrong-with-maven</link>
      <category>Java</category>
      <category>Programming</category>
      <category>maven</category>
      <category>buildr</category>
      <category>rant</category>
    </item>
    <item>
      <title>Kommandorad topp-tio</title>
      <description>&lt;p&gt;Gissa vilket &lt;span class="caps"&gt;CMS&lt;/span&gt; jag jobbar med&amp;#8230;&lt;/p&gt;


&lt;pre&gt;
  210    cd
   81    ls
   29    more
   28    ant
   25    bin/polopoly
   15    svn
   11    sudo
    9    pwd
    8    irb
    7    fgrep
&lt;/pre&gt;</description>
      <pubDate>Tue, 07 Oct 2008 11:31:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:122a9102-4718-43a6-a477-ad512f6cd18d</guid>
      <author>Anders</author>
      <link>http://www.ghostganz.com/blog/articles/2008/10/07/kommandorad-topp-tio</link>
      <category>Computers</category>
      <category>Programming</category>
    </item>
    <item>
      <title>Forgetting try-finally</title>
      <description>&lt;p&gt;or &lt;em&gt;&amp;#8220;Hot Potato Exception Handling&amp;#8221;&lt;/em&gt;&lt;/p&gt;


	&lt;p&gt;This is a common use of try-catch:&lt;/p&gt;


&lt;code&gt;
&lt;pre&gt;
public void foo() { 
    // Catch any exception so that the call to super is done anyway 
    try { 
        //... 
    } catch (Exception e) { 
        // Log
        // ...
    } 
    // Call super last 
    super.foo(); 
}
&lt;/pre&gt;
&lt;/code&gt;

	&lt;p&gt;You could think that the purpose of the try-catch is to enable logging of the exception. But the first comment (taken from actual example code) suggests that the logging is just incidental. The purpose is to make sure that something is run no matter what. The logging is just a case of not knowing anything better to do with the exception once it&amp;#8217;s caught.&lt;/p&gt;


	&lt;p&gt;Instead, why not use the simple &lt;strong&gt;try-finally&lt;/strong&gt;:&lt;/p&gt;


&lt;code&gt;
&lt;pre&gt;
public void foo() { 
    try { 
        //... 
    } finally {
        super.foo(); 
    }
} 
&lt;/pre&gt;
&lt;/code&gt;

	&lt;p&gt;We&amp;#8217;re not &amp;#8220;handling&amp;#8221; the exception, but that&amp;#8217;s probably good. We are handling non-&lt;code&gt;Exception&lt;/code&gt; throwables though. I think people just forget that you can have a try-finally without the catch.&lt;/p&gt;</description>
      <pubDate>Mon, 25 Aug 2008 15:06:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:06b88533-ac95-47ec-b404-082ce9c8ffc3</guid>
      <author>Anders</author>
      <link>http://www.ghostganz.com/blog/articles/2008/08/25/forgetting-try-finally</link>
      <category>Java</category>
      <category>Programming</category>
    </item>
    <item>
      <title>toString() is Evil</title>
      <description>&lt;p&gt;&lt;em&gt;...or some other provocative title.&lt;/em&gt;&lt;/p&gt;


	&lt;p&gt;The good old &lt;strong&gt;&lt;code&gt;toString()&lt;/code&gt;&lt;/strong&gt; method, with us since Java 1.0, has at least two different meanings:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;em&gt;Displaying&lt;/em&gt;: How the object should appear to the user, in the &lt;span class="caps"&gt;GUI&lt;/span&gt;, on a web page, etc.&lt;/li&gt;
		&lt;li&gt;&lt;em&gt;Inspection&lt;/em&gt;: How the object should appear in debug output, logs, debugger tools etc.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Both are in some way &amp;#8220;a string representation of the object&amp;#8221;. The default implementation in &lt;code&gt;java.lang.Object&lt;/code&gt; suggests inspection, e.g. &amp;#8220;&lt;code&gt;java.lang.Object@c37f31&lt;/code&gt;&amp;#8221;, but many APIs, like &lt;span class="caps"&gt;AWT&lt;/span&gt;/Swing, use it for displaying the object to the user.&lt;/p&gt;


	&lt;h4&gt;Problems&lt;/h4&gt;


	&lt;ul&gt;
	&lt;li&gt;It&amp;#8217;s hard to tell which usage is intended when reading the code.&lt;/li&gt;
		&lt;li&gt;Debuggers will use &lt;code&gt;toString()&lt;/code&gt;, which can cause confusing side-effects.&lt;/li&gt;
		&lt;li&gt;Since every object has a &lt;code&gt;toString()&lt;/code&gt;, the &lt;span class="caps"&gt;IDE&lt;/span&gt;&amp;#8217;s usage search becomes unusable.&lt;/li&gt;
		&lt;li&gt;It&amp;#8217;s hard to tell if a &lt;code&gt;toString()&lt;/code&gt; method is dead code or not.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;In addition, a lot of code implements it when it has a more specific meaning. For instance, generating &lt;span class="caps"&gt;HTML&lt;/span&gt; is better done as &lt;code&gt;toHTML()&lt;/code&gt; than as &lt;code&gt;toString()&lt;/code&gt;.&lt;/p&gt;


	&lt;h4&gt;What Others Do&lt;/h4&gt;


	&lt;p&gt;Ruby solves this differently than Java. There are two methods, &lt;strong&gt;&lt;code&gt;inspect()&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;to_s()&lt;/code&gt;&lt;/strong&gt;, where the default implementation of &lt;code&gt;to_s()&lt;/code&gt; in &lt;code&gt;Object&lt;/code&gt; uses &lt;code&gt;inspect()&lt;/code&gt;. This separates the two intentions, but still has &lt;code&gt;to_s()&lt;/code&gt; available on every object.&lt;/p&gt;


	&lt;p&gt;We can&amp;#8217;t do much about &lt;code&gt;java.lang.Object&lt;/code&gt;, but we still have options.&lt;/p&gt;


	&lt;h4&gt;Suggestion&lt;/h4&gt;


	&lt;p&gt;Use &lt;code&gt;toString()&lt;/code&gt; only for logging and debug output.&lt;/p&gt;


	&lt;p&gt;If the method has a more specific meaning, communicate that instead, e.g. &lt;code&gt;title()&lt;/code&gt; or &lt;code&gt;name()&lt;/code&gt;.&lt;/p&gt;


	&lt;p&gt;If the value to display has a specific format you can communicate that instead, e.g. &lt;code&gt;toHTML()&lt;/code&gt; or &lt;code&gt;asLeetSpeak()&lt;/code&gt;.&lt;/p&gt;


	&lt;p&gt;If the value to display is nothing other than a string, still avoid &lt;code&gt;toString()&lt;/code&gt;. Call it something like &lt;code&gt;displayString()&lt;/code&gt;, or maybe even &lt;code&gt;asString()&lt;/code&gt; to avoid problems.&lt;/p&gt;</description>
      <pubDate>Tue, 24 Jun 2008 18:00:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:1cc95189-2cf5-4791-a7ca-99f232e79f15</guid>
      <author>Anders</author>
      <link>http://www.ghostganz.com/blog/articles/2008/06/24/tostring-is-evil</link>
      <category>Java</category>
      <category>Programming</category>
    </item>
    <item>
      <title>BigDecimal performance notes</title>
      <description>&lt;p&gt;Notes on &lt;code&gt;java.math.BigDecimal&lt;/code&gt;&amp;#8217;s performance (in Java 1.5):&lt;/p&gt;


	&lt;h4&gt;Sorting&lt;/h4&gt;


	&lt;p&gt;BigDecimal&amp;#8217;s &lt;code&gt;compareTo&lt;/code&gt; method relies on both of the BigDecimals being in the same internal form. Internally BigDecimal uses either a BigInteger or, when possible, a native integer to represent its value. To compare two BigDecimals they&amp;#8217;re both normalized (&amp;#8220;inflated&amp;#8221;) to the BigInteger form. This means that simply sorting a list of BigDecimals can cause memory use to increase. Not what you&amp;#8217;d expect.&lt;/p&gt;


	&lt;h4&gt;Serialization&lt;/h4&gt;


	&lt;p&gt;Serialization of BigDecimal is surprisingly slow. Not only do they inflate their internal representation, just like when comparing, but they also use a lot of &lt;span class="caps"&gt;CPU&lt;/span&gt; for some reason. When serializing large graphs of objects of a lot of different classes, the BigDecimals stood out like a sore thumb in the &lt;span class="caps"&gt;CPU&lt;/span&gt; profile. Dumping them as String representations instead was quicker and didn&amp;#8217;t use as much memory.&lt;/p&gt;</description>
      <pubDate>Wed, 04 Jun 2008 13:47:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:64beba92-165c-4dde-b6ad-f516b6a88789</guid>
      <author>Anders</author>
      <link>http://www.ghostganz.com/blog/articles/2008/06/04/bigdecimal-performance-notes</link>
      <category>Java</category>
      <category>Programming</category>
      <category>performance</category>
    </item>
    <item>
      <title>Charles Miller on Maven</title>
      <description>&lt;p&gt;Charles Miller nicely &lt;a href="http://fishbowl.pastiche.org/2007/12/20/maven_broken_by_design"&gt;summarizes my opinions on Maven&lt;/a&gt;:&lt;/p&gt;


	&lt;blockquote&gt;
		&lt;p&gt;Paradoxically, by trying to make dependency management easy, maven makes it incredibly hard. It becomes dangerously easy for a project to accumulate dependency cruft &amp;#8211; at best unnecessary, at worst conflicting &amp;#8211; and excruciatingly painful to remove them.&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;Managing transitive dependencies by &lt;em&gt;automatically&lt;/em&gt; traversing the entire dependency tree, the basic strategy of Maven, must be an anti-pattern. Managing them &amp;#8220;manually&amp;#8221; is a little more work, but will probably save time in the end and definitely lower risk.&lt;/p&gt;</description>
      <pubDate>Thu, 20 Dec 2007 04:27:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:61e67949-ca92-4f92-952c-d0c5e1263665</guid>
      <author>Anders</author>
      <link>http://www.ghostganz.com/blog/articles/2007/12/20/charles-miller-on-maven</link>
      <category>Java</category>
      <category>Programming</category>
      <category>maven</category>
      <category>links</category>
    </item>
    <item>
      <title>JUnit Hidden Feature: Enclosed</title>
      <description>&lt;p&gt;&lt;em&gt;When JUnit 4.1 was released last year, they added a nice feature that has gone mostly unnoticed.&lt;/em&gt;&lt;/p&gt;


	&lt;h4&gt;RSpec envy&lt;/h4&gt;


	&lt;p&gt;Consider this archetypical &lt;a href="http://rspec.rubyforge.org/"&gt;RSpec&lt;/a&gt; example in Ruby. One class, Stack, being tested in two different scenarios (empty and non-empty):&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;
  describe Stack, " (empty)" do
    before(:each) do
      @stack = Stack.new
    end

    it "should have zero size" do
      @stack.size.should == 0
    end

    # ...
  end

  describe Stack, " (non-empty)" do
    before(:each) do
      @stack = Stack.new
      @stack.push 'x'
    end

    it "should have size greater than zero" do
      @stack.size.should &amp;gt; 0
    end

    # ...
  end
&lt;/pre&gt;
&lt;/code&gt;

	&lt;p&gt;Doing the same thing in &lt;a href="http://www.junit.org/"&gt;JUnit&lt;/a&gt; would require us to either create two different classes, which makes our tests hard to follow, or to abandon the &amp;#8220;before&amp;#8221;-methods and initializing at the start of each test method. Other tools, like &lt;a href="http://www.jdave.org/"&gt;JDave&lt;/a&gt;, solve this by having an inner class for each scenario, but for various reasons JDave isn&amp;#8217;t the solution for me.&lt;/p&gt;


	&lt;h4&gt;Enclosed to the rescue&lt;/h4&gt;


	&lt;p&gt;When browsing the JUnit source code, my colleague Rickard stumbled on the &lt;code&gt;org.junit.runners.Enclosed&lt;/code&gt; class. Apparently it&amp;#8217;s been part of JUnit since 4.1 released in 2006. &lt;code&gt;Enclosed&lt;/code&gt; is a test runner that runs all the inner classes of a class as tests. It works perfectly within IntelliJ and other tools. Now you can have Rspec-style testing in JUnit, almost. Behold its goodness:&lt;/p&gt;


&lt;code&gt;
&lt;pre&gt;

@RunWith(org.junit.runners.Enclosed.class)
public class StackTest {

    public static class EmptyStack {
        private Stack stack;

        @Before
        public void before() {
            stack = new Stack();
        }

        @Test
        public void shouldHaveZeroSize() {
            assertEquals(0, stack.size());
        }

        // ...
    }

    public static class NonEmptyStack {
        private Stack stack;

        @Before
        public void before() {
            stack = new Stack();
            stack.push("x");
        }

        @Test
        public void shouldHaveSizeGreaterThanZero() {
            assertTrue(stack.size() &amp;gt; 0);
        }

        // ...
    }
}

&lt;/pre&gt;
&lt;/code&gt;</description>
      <pubDate>Fri, 14 Sep 2007 11:11:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:a6951b8a-3c0c-47a9-822c-b7c59145cb77</guid>
      <author>Anders</author>
      <link>http://www.ghostganz.com/blog/articles/2007/09/14/junit-hidden-feature-enclosed</link>
      <category>Java</category>
      <category>Programming</category>
      <category>junit</category>
      <category>jdave</category>
      <category>rspec</category>
      <category>testing</category>
      <category>bdd</category>
    </item>
    <item>
      <title>The Commercial Constraint</title>
      <description>&lt;h4&gt;Open Source, System Architecture and Centralization&lt;/h4&gt;


	&lt;p&gt;&lt;em&gt;Thoughts on how Open Source software affects system architecture. Or, to be more precise, how the lack of per-server licensing affects it.&lt;/em&gt;&lt;/p&gt;


	&lt;p&gt;Last year, as an example, I worked on &lt;a href="http://www.ghostganz.com/blog/articles/2006/10/03/jms-messaging-observations"&gt;a project&lt;/a&gt; using &lt;span class="caps"&gt;JMS&lt;/span&gt; messaging. Originally the plan was to send messages to a local message broker application on the sending system (2-3 servers), through central message brokers in two data-centers (2-4 servers) and possibly brokers on every receiving system (lots and lots). Obviously we were planning to use an Open Source message broker, because if we had considered using a commercial product, we would never have come up with an architecture with so many brokers.&lt;/p&gt;


	&lt;p&gt;When the project was underway we had to switch to a commercial &lt;span class="caps"&gt;JMS&lt;/span&gt; broker. These products are big, &amp;#8220;enterprisey&amp;#8221; and expensive things, so suddenly we could only practically have four central servers, and they still would cost us a fortune. The result? Among other things worse performance, since the round-trip time to the central servers was longer than talking to a local broker. Even though the commercial software had much better high-availability support, the system was in practice more vulnerable because of its centralization. (Fortunately availability never became an issue, since the project failed and never reached production&amp;#8230;)&lt;/p&gt;


	&lt;p&gt;Another, much better, example is Google. What would Microsoft charge them to run Windows on half a million servers? The kind of massively parallel architecture that Google use did exist early, but it wasn&amp;#8217;t until the freely available Linux was available that it became popular, e.g. Beowulf clustering. Suddenly you could build a super-computer out of scrap hardware, something you earlier wouldn&amp;#8217;t dream of.&lt;/p&gt;


	&lt;p&gt;When you can design your systems free of the licensing constraint, they tend to become more decentralized. Even though the total cost of a decentralized architecture may not be prohibitive, I think you subconsciously lean towards the centralized solutions when per-server licensing is in the picture. For such a major design constraint, it&amp;#8217;s rarely put into numbers or even mentioned.&lt;/p&gt;</description>
      <pubDate>Fri, 07 Sep 2007 16:58:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:a1195332-fd1f-4fc8-b78a-ed72baf89a92</guid>
      <author>Anders</author>
      <link>http://www.ghostganz.com/blog/articles/2007/09/07/the-commercial-constraint</link>
      <category>Java</category>
      <category>Programming</category>
      <category>jms</category>
      <category>architecture</category>
      <category>oss</category>
    </item>
    <item>
      <title>Links: Great Programming Articles</title>
      <description>&lt;p&gt;Just so I don&amp;#8217;t have to search for them again the next time I need someone to read them:&lt;/p&gt;


	&lt;h4&gt;&lt;a href="http://www.pragmaticprogrammer.com/ppllc/papers/1998_05.html"&gt;Tell, Don&amp;#8217;t Ask&lt;/a&gt;&lt;/h4&gt;


	&lt;p&gt;The Pragmatic Programmers show in simple words how to do good OO design, as they explain the Law of Demeter.&lt;/p&gt;


	&lt;h4&gt;&lt;a href="http://www.objectmentor.com/resources/articles/dip.pdf"&gt;The Dependency Inversion Principle&lt;/a&gt;&lt;/h4&gt;


	&lt;p&gt;Robert C. Martin on how to manage dependencies between classes and layers. (Don&amp;#8217;t confuse it with Dependency &lt;em&gt;Injection&lt;/em&gt;).&lt;/p&gt;</description>
      <pubDate>Sun, 26 Aug 2007 03:55:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:abf9e9bf-577d-4869-a903-4ebb2b50c59f</guid>
      <author>Anders</author>
      <link>http://www.ghostganz.com/blog/articles/2007/08/26/links-great-programming-articles</link>
      <category>Programming</category>
      <category>links</category>
    </item>
    <item>
      <title>Terracotta Clustering Observations</title>
      <description>&lt;p&gt;I&amp;#8217;m currently developing a clustered back-end system for a website using &lt;a href="http://www.terracotta.org/"&gt;Terracotta&lt;/a&gt;. Not yet in production, but here are some random observations so far:&lt;/p&gt;


	&lt;h3&gt;Transparency&lt;/h3&gt;


	&lt;p&gt;The same old &amp;#8220;transparency&amp;#8221; that every new framework claims? Yes and no.&lt;/p&gt;


	&lt;p&gt;You can&amp;#8217;t ignore that you&amp;#8217;re writing a clustered app. There are performance concerns, memory usage, some obscurer parts of the Java &lt;span class="caps"&gt;API&lt;/span&gt; that&amp;#8217;s unsupported, etc. There&amp;#8217;s details that you must know, so you really have to read the documentation. You also have to configure Terracotta for your application.&lt;/p&gt;


	&lt;p&gt;But after you&amp;#8217;ve grasp the basic idea about how the clustering works, it&amp;#8217;s pretty straightforward. When you have a Terracotta-friendly overall architecture going, the day-to-day work with business logic details isn&amp;#8217;t much affected by it.&lt;/p&gt;


	&lt;h3&gt;Testing&lt;/h3&gt;


	&lt;p&gt;Since Terracotta &lt;em&gt;doesn&amp;#8217;t have an &lt;span class="caps"&gt;API&lt;/span&gt;&lt;/em&gt;, unit testing the application is very simple. There&amp;#8217;s nothing that requires mocking and things work the same with or without clustering. You can unit test as if Terracotta didn&amp;#8217;t exist, which is much better than your average framework. I think the ease of unit testing is one of the strongest points of Terracotta.&lt;/p&gt;


	&lt;p&gt;Since you&amp;#8217;re unit testing without the cluster, there&amp;#8217;s still a lot of functional testing required to make sure things really work. It does happen that things break when you run them clustered. But most problems we&amp;#8217;ve seen are easily fixed configuration problems, or threading issues that we would have even without clustering.&lt;/p&gt;


	&lt;h3&gt;Threading&lt;/h3&gt;


	&lt;p&gt;Since Terracotta follows Java&amp;#8217;s &amp;#8220;memory model&amp;#8221;, you just have to write a correctly threaded Java application for it to work. Unfortunately it&amp;#8217;s very tricky to write such a thing.
The kind of sloppy thread programming you can often get away with, without any observable bugs, will not work. Fortunately Terracotta will catch a lot of problems directly, but you still have to have a good insight into Java threads to get things right. This ain&amp;#8217;t Erlang.&lt;/p&gt;


	&lt;h3&gt;Performance&lt;/h3&gt;


	&lt;p&gt;The throughput and transaction rate looks good, you can do a lot of changes per second. For our application, with a big data-set, we&amp;#8217;ve instead found the &amp;#8220;virtual heap&amp;#8221; speed to be what limits us. Paging in data from the server to the cluster nodes takes time. You can add new objects to the shared heap faster than you can page in old ones. This means we have to optimize our application for localized memory access. No real surprise.&lt;/p&gt;


	&lt;h3&gt;Other&lt;/h3&gt;


	&lt;p&gt;We&amp;#8217;ve run into a few problems, small and big, but they&amp;#8217;ve been quickly resolved with the help of the mailing list.&lt;/p&gt;</description>
      <pubDate>Sun, 08 Jul 2007 15:50:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:d5678140-1d7e-4113-bf87-bdfee1452a8e</guid>
      <author>Anders</author>
      <link>http://www.ghostganz.com/blog/articles/2007/07/08/terracotta-clustering-observations</link>
      <category>Java</category>
      <category>Programming</category>
      <category>terracotta</category>
    </item>
  </channel>
</rss>
