<?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 Java</title>
    <link>http://www.ghostganz.com/blog/articles/category/java</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>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>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>
    <item>
      <title>What do we want the software to do?</title>
      <description>&lt;p&gt;About intentions, two stages in the history of programming and the corresponding stages in the individual programmer&amp;#8217;s skills.&lt;/p&gt;


	&lt;h3&gt;Stage A &amp;#8211; How do I get it to do what I want?&lt;/h3&gt;


	&lt;p&gt;In the beginning of a programmer&amp;#8217;s learning there is a struggle to simply get the machine to do something, &lt;em&gt;anything&lt;/em&gt;. Much like when you try to communicate in a spoken language you&amp;#8217;ve just started learning, you can&amp;#8217;t express some concepts, invent awkward statements instead of words you don&amp;#8217;t know, and get things plain wrong.
You have a pretty clear idea what you want to say, but you struggle to communicate it.&lt;/p&gt;


	&lt;blockquote&gt;
		&lt;p&gt;&amp;#8220;I need a lift in your el truck-o to the next town-o!&amp;#8221;&amp;#8212;Brad Pitt, &lt;em&gt;The Mexican&lt;/em&gt;&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;In the early programming languages, there wasn&amp;#8217;t much more to it than this. The language was very limited and even though it could theoretically express everything, you couldn&amp;#8217;t &lt;em&gt;communicate&lt;/em&gt; it. The higher level concepts and ideas was not expressed in the language, but in the documentation or, more likely, remained in the programmer&amp;#8217;s head. Even though you learn the language to perfection, there&amp;#8217;s little difference in what you can express.&lt;/p&gt;


	&lt;h3&gt;Stage B &amp;#8211; What do I want?&lt;/h3&gt;


	&lt;blockquote&gt;
		&lt;p&gt;&amp;#8220;I want a helmet. A cheese helmet. A helmet full of cheese. You just pop it on your head and eat all day.&amp;#8221;&amp;#8212;Denis Leary&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;Once you master a language, the focus shifts away from the language itself. If you know what you want to say, you can often express it directly, less limited by the language. Ever higher levels of abstraction and expressiveness in languages makes this increasingly simple. (Learning the language in the first place isn&amp;#8217;t necessarily any simpler). Constructs like classes allow you to express very abstract concepts and ideas in just a few statements.&lt;/p&gt;


	&lt;p&gt;The original purpose of a language, &lt;em&gt;communication&lt;/em&gt;, can now be achieved. The problem is now to find out what you want, your &lt;em&gt;intention&lt;/em&gt;, so that you can express it.&lt;/p&gt;


	&lt;h3&gt;Understanding and Documentation&lt;/h3&gt;


	&lt;p&gt;While most of what programmers do these days is firmly in &amp;#8220;B&amp;#8221;, there are a lot of ideas with roots in &amp;#8220;A&amp;#8221; that still linger in our minds. Our ideas about how and when to document our code often have their origins in a time where the languages couldn&amp;#8217;t serve the purpose of communication. There was no option but to annotate everything with natural language if you wanted to communicate. When we left machine code for procedural languages this need was reduced a lot (to merely procedure-level comments), and object-oriented languages reduced even further (maybe to just class-level comments). This is all under the assumption that the language&amp;#8217;s abilities are actually used.&lt;/p&gt;


	&lt;p&gt;The intensive documentation required in &amp;#8220;A&amp;#8221; also sometimes created the belief that the documentation should be extensive enough for someone, with no prior knowledge of the system, to understand it directly.
But just like in any natural language, the individual statements don&amp;#8217;t make sense unless you know their context. In a program the context can be very big, ranging from knowledge about the problem domain to the technical solutions preferred in the programming team and can not be expected to be learned from low-level documentation within the code.
The purpose of the code is communication with the other programmers working on the system (and with the compiler). Like any natural language, you use people&amp;#8217;s shared context to make the communication more efficient, at the expense of the outsider&amp;#8217;s understanding of it.&lt;/p&gt;


	&lt;h3&gt;Getting to B&lt;/h3&gt;


	&lt;blockquote&gt;
		&lt;p&gt;&amp;#8220;&lt;code&gt;I CAN WRITE COBOL IN ANY LANGUAGE&lt;/code&gt;&amp;#8221;&amp;#8212;Unknown&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;While a beginner may naturally be in &amp;#8220;A&amp;#8221;, there is no guarantee that experienced programmers will be in &amp;#8220;B&amp;#8221;. While it is a requirement to know the language well to do &amp;#8220;B&amp;#8221;-style programming, it isn&amp;#8217;t enough. Just using a modern language doesn&amp;#8217;t make our code more communicative. We can still write long methods with three-letter variable names in Java, as we did in C. We can still organize and name our Ruby classes entirely without connection to our problem domain.&lt;/p&gt;


	&lt;p&gt;We have to strive to keep accidental complexity and technicalities to creep into how we write and organize our code. Using good naming on everything from variables up to modules, we have to keep the code close to the intentions that originate it. When the intentions change, we have to use Refactoring to make the code reflect the new conditions. If we don&amp;#8217;t use these new opportunities, we&amp;#8217;re also stuck with the needs for heavy documentation and other practices of &amp;#8220;A&amp;#8221;. Even if we don&amp;#8217;t write code for the &amp;#8220;outsider&amp;#8221; audience, we still need to communicate as clearly as possible.&lt;/p&gt;


	&lt;h3&gt;&amp;#8220;Getting the words right&amp;#8221;&lt;/h3&gt;


	&lt;p&gt;The big challenge is to know what your intentions really are. Unless they are truly clear in our minds, they can&amp;#8217;t be clear in the code. This is where design tools like Test-Driven Development (TDD) is a big help. By forcing us to reason and express what we really want our code to do, it makes it easier to write code that also communicates this intention.
The more recent &lt;a href="http://behaviour-driven.org/"&gt;Behavior-Driven Development&lt;/a&gt; (BDD) concept emphasizes the &lt;span class="caps"&gt;TDD&lt;/span&gt; idea that the tests themselves should be used for communication. &lt;a href="http://rspec.rubyforge.org/"&gt;&lt;span class="caps"&gt;BDD&lt;/span&gt; tools&lt;/a&gt; typically encourage you to state your intentions in natural language, together with code that verifies each intention (paradoxically similar to the early documentation practices). Unlike other forms of documentation, it is harder for this one to become out-of-date and misleading.&lt;/p&gt;


	&lt;p&gt;The &lt;span class="caps"&gt;TDD&lt;/span&gt;/BDD ideas seems like a parallel, but orthogonal, development to that of the modern languages. They are adding more ways of communication, but at the same time as helping us use the existing ways better.&lt;/p&gt;


	&lt;h3&gt;Thus&lt;/h3&gt;


	&lt;p&gt;There are a lot of opportunities in &amp;#8220;B&amp;#8221;, as long as you actually take advantage of them. For novices, there is the need to master their programming language, to gain the ability to express themselves in it. For experienced programmers, it&amp;#8217;s important to really use the abilities to communicate that modern languages provide, supported by the available tools.&lt;/p&gt;</description>
      <pubDate>Sun, 01 Jul 2007 16:20:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:13e223fb-6b64-4139-a2ab-63561623bd53</guid>
      <author>Anders</author>
      <link>http://www.ghostganz.com/blog/articles/2007/07/01/what-do-we-want-the-software-to-do</link>
      <category>Ruby</category>
      <category>Java</category>
      <category>Programming</category>
      <category>rambling</category>
      <category>language</category>
    </item>
    <item>
      <title>Classic Java Method Dispatching Anger</title>
      <description>&lt;p&gt;&lt;strong&gt;On a common trap that a lot of us have walked into as our Java skills deepened:&lt;/strong&gt;&lt;/p&gt;


	&lt;p&gt;You&amp;#8217;re solving some programming problem involving multiple types/classes when you realize that you can make great use of Java&amp;#8217;s method overloading. Just implement one method for each of the classes, and you&amp;#8217;re done! In this example, two subclasses of &lt;code&gt;Person&lt;/code&gt;:&lt;/p&gt;


	&lt;pre&gt;&lt;code&gt;void doStuff(Worker worker) {
   ...
}&lt;/code&gt;&lt;/pre&gt;


	&lt;pre&gt;&lt;code&gt;void doStuff(Capitalist capitalist) {
   ...
}&lt;/code&gt;&lt;/pre&gt;


	&lt;p&gt;Now if you just call &lt;code&gt;doStuff&lt;/code&gt; like this:&lt;/p&gt;


	&lt;pre&gt;&lt;code&gt;Person person = ...
x.doStuff(person);&lt;/code&gt;&lt;/pre&gt;


	&lt;p&gt;it should all work, right? It should call the correct method, depending on which class &lt;code&gt;person&lt;/code&gt; is. You probably feel a slight rush of pride when you look at how simple your solution is.&lt;/p&gt;


	&lt;p&gt;But of course it &lt;strong&gt;doesn&amp;#8217;t work&lt;/strong&gt;. Java&amp;#8217;s method calls must have their argument types known at compile-time&lt;sup&gt;&lt;a href="#fn1"&gt;1&lt;/a&gt;&lt;/sup&gt;. You need to have &lt;code&gt;person&lt;/code&gt; cast to one of the subclasses, otherwise the compiler will complain that it doesn&amp;#8217;t know which of the two methods you mean. You mean &amp;#8220;either&amp;#8221;, but the compiler can&amp;#8217;t help you.&lt;/p&gt;


	&lt;p&gt;At this point there is often bitter disappointment and anger, usually directed at the compiler or language (&lt;em&gt;&amp;#8220;jävla skitspråk!&amp;#8221;&lt;/em&gt;). Once that subsides, you know you have learned something. Even programmers with good knowledge of Java seem to walk into this trap, which is what made me notice this phenomenon. Even though you know all the theory of how Java works, you can still get surprised by the practical implications.&lt;/p&gt;


	&lt;p&gt;For me, it was around 1999 at my first job. I can&amp;#8217;t remember the problem I was trying to solve, but I do remember the surprise and disappointment. I last witnessed it just a few weeks ago. When I mentioned the phenomenon to a friend, he recalled having gone through it himself, and also having witnessed it recently.&lt;/p&gt;


	&lt;p&gt;Does everyone go through this when they&amp;#8217;re learning Java?&lt;/p&gt;


	&lt;p id="fn1"&gt;&lt;sup&gt;1&lt;/sup&gt; This doesn&amp;#8217;t happen with dynamically typed languages, since they typically bind their methods at run-time. On the other hand most dynamically typed languages don&amp;#8217;t do method dispatching on &lt;em&gt;types&lt;/em&gt; at all. Some functional languages with fancier method dispatchers can do this stuff, maybe at the expense of slower method calls. Erlang&amp;#8217;s pattern matching of messages takes this feature to the extreme (though it&amp;#8217;s not exactly method calls). You could argue that Prolog is the very extreme of this, where &lt;em&gt;everything&lt;/em&gt; is fancy method dispatching.&lt;/p&gt;</description>
      <pubDate>Fri, 18 May 2007 19:20:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:d70739d4-7da0-4ac9-82bc-a78223d65c39</guid>
      <author>Anders</author>
      <link>http://www.ghostganz.com/blog/articles/2007/05/18/classic-java-method-dispatching-anger</link>
      <category>Java</category>
      <category>Programming</category>
      <category>languages</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
