<?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</title>
    <link>http://www.ghostganz.com/blog/</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>Back up</title>
      <description>&lt;p&gt;After a disk failure in my MacBook, here are some observations on &lt;a href="http://jwz.livejournal.com/801607.html"&gt;bootable backup disks&lt;/a&gt;:&lt;/p&gt;


	&lt;p&gt;1. Verify beforehand that your bootable backup disk actually is bootable.&lt;/p&gt;


	&lt;p&gt;2. Having a replacement disk ready means less when you don&amp;#8217;t have the Torx T8 screwdriver needed to install it.&lt;/p&gt;


	&lt;p&gt;3. Torx screws are an evil conspiracy.&lt;/p&gt;


	&lt;p&gt;4. Having a working &lt;span class="caps"&gt;DVD&lt;/span&gt; reader will save you time and money when re-installing the OS.&lt;/p&gt;


	&lt;p&gt;But I luckily made the last backup just 24h before the crash, so I lost almost nothing.&lt;/p&gt;</description>
      <pubDate>Sat, 06 Sep 2008 19:06:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:7ddc4414-caf1-4c6e-9500-2df275d8255c</guid>
      <author>Anders</author>
      <link>http://www.ghostganz.com/blog/articles/2008/09/06/back-up</link>
      <category>Computers</category>
      <category>backups</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>Animal</title>
      <description>&lt;p&gt;&lt;a href="http://www.flickr.com/photos/ghostganz/2740683185/" title="Animal by Ghost Ganz, on Flickr"&gt;&lt;img src="http://farm4.static.flickr.com/3152/2740683185_1d95948ae5.jpg" width="500" height="281" alt="Animal" /&gt;&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Thu, 07 Aug 2008 09:32:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:c2ea39d1-8f5a-4ccf-9fd1-9250d21b0097</guid>
      <author>Anders</author>
      <link>http://www.ghostganz.com/blog/articles/2008/08/07/animal</link>
      <category>Photo</category>
      <category>rock n roll</category>
    </item>
    <item>
      <title>&amp;quot;Street and Studio&amp;quot; @ Tate Modern</title>
      <description>&lt;p&gt;Last week I saw the &lt;a href="http://www.tate.org.uk/modern/exhibitions/streetandstudio/default.shtm"&gt;Street and Studio&lt;/a&gt; photo exhibition at Tate Modern in London. Lots of great photos from the 1800&amp;#8217;s up to current time, including the 1900&amp;#8217;s favorites I already knew, like Walker Evans, Diane Arbus and others. But it also served as an interesting introduction to later photographers like Martin Parr and Rineke Dijkstra, at least for someone like me who was stuck in the 20th century.&lt;/p&gt;


	&lt;p&gt;If you&amp;#8217;re in London before 31 August 2008, go see it!&lt;/p&gt;</description>
      <pubDate>Sun, 06 Jul 2008 09:21:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:e3103b41-29ac-4630-8989-41d6a996dcc3</guid>
      <author>Anders</author>
      <link>http://www.ghostganz.com/blog/articles/2008/07/06/street-and-studio-tate-modern</link>
      <category>Photo</category>
      <category>exhibitions</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>New job</title>
      <description>&lt;p&gt;I&amp;#8217;ll be starting a new job at Valtech this summer!&lt;/p&gt;


	&lt;p&gt;After three years at PriceRunner it felt like it was time to move on. I&amp;#8217;ve done a lot of interesting projects and the people are great, but I need some new challenges. I&amp;#8217;ll probably be doing a lot of the same things, but doing it in the role of a consultant will be new. I&amp;#8217;m also hoping to do a bit more front-end web development, to balance all the back-end system work I&amp;#8217;ve done lately.&lt;/p&gt;


	&lt;p&gt;But first: Summer vacation!&lt;/p&gt;</description>
      <pubDate>Sun, 25 May 2008 16:11:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:1a54d9a9-8446-4199-809e-3abd9a5fd95b</guid>
      <author>Anders</author>
      <link>http://www.ghostganz.com/blog/articles/2008/05/25/new-job</link>
      <category>work</category>
    </item>
    <item>
      <title>Idly twittering away</title>
      <description>&lt;p&gt;I&amp;#8217;ve started to use &lt;a href="http://twitter.com/ghostganz"&gt;Twitter&lt;/a&gt;. We&amp;#8217;ll see how it works out.&lt;/p&gt;</description>
      <pubDate>Wed, 30 Apr 2008 07:50:28 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:02cfe731-5175-4346-ae1b-5f425fefc790</guid>
      <author>Anders</author>
      <link>http://www.ghostganz.com/blog/articles/2008/04/30/idly-twittering-away</link>
    </item>
  </channel>
</rss>
