<?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>NewInstance &#187; Horror Code</title>
	<atom:link href="http://en.newinstance.it/category/horror-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://en.newinstance.it</link>
	<description>Welcome to the official blog of Luigi R. Viggiano. Beware of imitations.</description>
	<lastBuildDate>Mon, 09 Jan 2012 20:29:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Shall configuration be bound to the underlying of your application?</title>
		<link>http://en.newinstance.it/2008/10/26/shall-configuration-be-bound-to-the-underlying-of-your-application/</link>
		<comments>http://en.newinstance.it/2008/10/26/shall-configuration-be-bound-to-the-underlying-of-your-application/#comments</comments>
		<pubDate>Sun, 26 Oct 2008 21:55:26 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
				<category><![CDATA[Horror Code]]></category>

		<guid isPermaLink="false">http://en.newinstance.it/2008/10/26/shall-configuration-be-bound-to-the-underlying-of-your-application/</guid>
		<description><![CDATA[Welcome to anti-refactoring lesson number 4. Previously I posted about trivial programming errors, stuff for amateur programmers as in last case. Here we go for a more conceptual mistake. Answer this question: from 1 to 10, how do you think it's smart to bind the name of a configuration property to the internals of your [...]]]></description>
			<content:encoded><![CDATA[<p><!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic -->Welcome to anti-refactoring lesson number 4.</p>
<p>Previously I posted about trivial programming errors, stuff for amateur programmers as in last case. Here we go for a more conceptual mistake. </p>
<p>Answer this question: from 1 to 10, how do you think it's smart to bind the name of a configuration property to the internals of your application?<br />
In my opinion -1. Here I am going to tell you why.</p>
<h4>What is god</h4>
<p>The configuration is a business aspect your application. And one of the primary goals of a configuration property is to tell the user what application behavior he is modifying. So if the user finds a property like:</p>
<pre>
myapp.splashscreen.display.seconds=5
</pre>
<p>The user can understand that he is going to change the amount of time for which the splash screen will be displayed. And, also very important, the user can understand that the option value must be expressed in seconds.</p>
<p>Then, in your code you will have:</p>
<pre class="java"><span class="line_number">1</span><span class="code">Property configuration = ...
<span class="line_number">2</span><span class="java_primitive_type">long</span> splashDelaySeconds = configuration.getProperty<span class="parenthesis">(</span><span class="string_constant">&quot;myapp.splashscreen.display.seconds&quot;</span><span class="parenthesis">)</span>;</span>
</pre>
<p>Notice that there is a 1 to 1 mapping between the property key declared in the configuration file and the key used in the source code referring to that. This allows modern IDE, like Eclipse, to navigate from the property file to the places on the source code where the property is used. If you never used it, try yourself: open a property file in eclipse and press CTRL clicking with the mouse over a property key; you'll see all the places in your code where that property key is referenced. If your IDE doesn't offer this facility, you can still do a full text search, using the property key, and you'll be able to understand how that configuration property is used.</p>
<h4>What is bad</h4>
<p>You may be unlucky like me, and get above approach anti-refactored using the following collection of bad practices. </p>
<p><strong>First</strong>: including a package name, or any other internals, into the property name.<br />
So you will have configuration properties like this: </p>
<pre>
com.acme.blahblah.myapp.splashscreen.delay=5000
</pre>
<p>Much more cryptic for almost everyone.</p>
<p>Not only: if your application internals change, also the option name changes. And there is no reason to change the same option across different software versions if the option is specifying the same behavior.</p>
<p><strong>Second</strong>: notice that the time unit is gone. With the assumption that everything is expressed in milliseconds. Thing that could seem very obvious to some "experts", but believe me it is not obvious at all, when in a large system options became hundreds and nobody knows not only the unit of measures, but also what the hell they are supposed to do.</p>
<p><strong>Third</strong>: breaking the property key mapping between configuration file and source code. So you will have:</p>
<pre class="java"><span class="line_number">1</span><span class="code">Property configuration = ...
<span class="line_number">2</span><span class="java_primitive_type">long</span> splashDelaySeconds = configuration.getProperty<span class="parenthesis">(</span>getPrefix<span class="parenthesis">()</span> + <span class="string_constant">&quot;.myapp.splashscreen.delay&quot;</span><span class="parenthesis">)</span>;
<span class="line_number">3</span>...</span>
</pre>
<p>No more "search" will be effective; the developers that maintain that code have to go crazy searching portions of the key, and guessing how the original developer constructed that. It's an extremely enjoyable way to spend your work time, I had this luck before and I can assure you.</p>
<p>Summarizing, the above example, including the package name (or the classname, or other stuff related to the implementation) in the property name is wrong for many reasons:</p>
<ol>
<li> You are binding a business behavior of your application (the configuration) to the internal implementation</li>
<li> The same property may be used by classes contained in different packages, so the package name doesn't add any useful information (because it also becomes a wrong information)</li>
<li> Mere implementation changes should not be impacting how clients use the software. If you move a class from a package to another... should you update the configuration files? Why?</li>
<li> You break the 1 to 1 mapping between the keys specified in the property file and your souce code. Not having that it will become hard to find how a configuration property is used by the code.</li>
</ol>
<p>So... don't do it.
<div id="crp_related">
<h4>Related Posts:</h4>
<ul>
<li><a href="http://en.newinstance.it/2008/10/24/always-on-getter-and-setters/" rel="bookmark" class="crp_title">Always on getter and setters</a></li>
<li><a href="http://en.newinstance.it/2008/06/21/displaying-version-in-a-maven-based-project/" rel="bookmark" class="crp_title">Displaying the version in a Maven-based project</a></li>
<li><a href="http://en.newinstance.it/2008/11/04/dynamic-tests-with-junit-3/" rel="bookmark" class="crp_title">Dynamic tests with JUnit 3</a></li>
<li><a href="http://en.newinstance.it/2008/10/24/the-repetita-juvant-principle/" rel="bookmark" class="crp_title">The Repetita Juvant Principle</a></li>
<li><a href="http://en.newinstance.it/2006/11/19/reading-javadocs-from-inside-the-original-zip-file/" rel="bookmark" class="crp_title">Reading Javadocs from inside the original zip file</a></li>
</ul>
</div>
<div class="shr-publisher-332"></div>
<p><!-- Start Shareaholic LikeButtonSetBottom Automatic -->
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2008%2F10%2F26%2Fshall-configuration-be-bound-to-the-underlying-of-your-application%2F' data-shr_title='Shall+configuration+be+bound+to+the+underlying+of+your+application%3F'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2008%2F10%2F26%2Fshall-configuration-be-bound-to-the-underlying-of-your-application%2F' data-shr_title='Shall+configuration+be+bound+to+the+underlying+of+your+application%3F'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2008%2F10%2F26%2Fshall-configuration-be-bound-to-the-underlying-of-your-application%2F' data-shr_title='Shall+configuration+be+bound+to+the+underlying+of+your+application%3F'></a></div>
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<p><!-- End Shareaholic LikeButtonSetBottom Automatic --></p>
]]></content:encoded>
			<wfw:commentRss>http://en.newinstance.it/2008/10/26/shall-configuration-be-bound-to-the-underlying-of-your-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Repetita Juvant Principle</title>
		<link>http://en.newinstance.it/2008/10/24/the-repetita-juvant-principle/</link>
		<comments>http://en.newinstance.it/2008/10/24/the-repetita-juvant-principle/#comments</comments>
		<pubDate>Fri, 24 Oct 2008 15:36:07 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
				<category><![CDATA[Horror Code]]></category>

		<guid isPermaLink="false">http://en.newinstance.it/2008/10/24/the-repetita-juvant-principle/</guid>
		<description><![CDATA[Welcome to anti-refactoring lesson number 3. The "Repetita Juvant Principle" is the counterpart of the DRY principle: 1 @Override 2 public SomeObject getSomeObject() { 3 return super.getSomeObject(); 4 } 5 6 @Override 7 public void setSomeObject(SomeObject arg0) { 8 super.setSomeObject( arg0 ); 9 } Then, you may think... this code has been written for some [...]]]></description>
			<content:encoded><![CDATA[<p><!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic -->Welcome to anti-refactoring lesson number 3.</p>
<p>The "Repetita Juvant Principle" is the counterpart of the  <a href="http://en.wikipedia.org/wiki/DRY">DRY principle</a>:</p>
<pre class="java"><span class="line_number">1</span><span class="code">    <span class="java_annotation">@Override</span>
<span class="line_number">2</span>    <span class="java_keyword">public</span> SomeObject getSomeObject<span class="parenthesis">()</span> <span class="parenthesis">{</span>
<span class="line_number">3</span>        <span class="java_keyword">return</span> <span class="java_keyword">super</span>.getSomeObject<span class="parenthesis">()</span>;
<span class="line_number">4</span>    <span class="parenthesis">}</span>
<span class="line_number">5</span>
<span class="line_number">6</span>    <span class="java_annotation">@Override</span>
<span class="line_number">7</span>    <span class="java_keyword">public</span> <span class="java_primitive_type">void</span> setSomeObject<span class="parenthesis">(</span>SomeObject arg0<span class="parenthesis">)</span> <span class="parenthesis">{</span>
<span class="line_number">8</span>        <span class="java_keyword">super</span>.setSomeObject<span class="parenthesis">(</span> arg0 <span class="parenthesis">)</span>;
<span class="line_number">9</span>    <span class="parenthesis">}</span></span>
</pre>
<p>Then, you may think... this code has been written for some purpose, right? The only purpose of this code could be to expose as public a method that is protected on the superclass. So I checked the superclass and, guess what...? The methods were already public! Simply fantastic.
<div id="crp_related">
<h4>Related Posts:</h4>
<ul>
<li><a href="http://en.newinstance.it/2008/10/24/always-on-getter-and-setters/" rel="bookmark" class="crp_title">Always on getter and setters</a></li>
<li><a href="http://en.newinstance.it/2008/11/04/dynamic-tests-with-junit-3/" rel="bookmark" class="crp_title">Dynamic tests with JUnit 3</a></li>
<li><a href="http://en.newinstance.it/2008/11/22/random-thoughts-about-unchecked-exceptions/" rel="bookmark" class="crp_title">Random thoughts about unchecked exceptions</a></li>
<li><a href="http://en.newinstance.it/2008/10/22/programmers-like-writing-dumb-code/" rel="bookmark" class="crp_title">Programmers like writing dumb code</a></li>
<li><a href="http://en.newinstance.it/2006/11/19/reading-javadocs-from-inside-the-original-zip-file/" rel="bookmark" class="crp_title">Reading Javadocs from inside the original zip file</a></li>
</ul>
</div>
<div class="shr-publisher-331"></div>
<p><!-- Start Shareaholic LikeButtonSetBottom Automatic -->
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2008%2F10%2F24%2Fthe-repetita-juvant-principle%2F' data-shr_title='The+Repetita+Juvant+Principle'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2008%2F10%2F24%2Fthe-repetita-juvant-principle%2F' data-shr_title='The+Repetita+Juvant+Principle'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2008%2F10%2F24%2Fthe-repetita-juvant-principle%2F' data-shr_title='The+Repetita+Juvant+Principle'></a></div>
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<p><!-- End Shareaholic LikeButtonSetBottom Automatic --></p>
]]></content:encoded>
			<wfw:commentRss>http://en.newinstance.it/2008/10/24/the-repetita-juvant-principle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Always on getter and setters</title>
		<link>http://en.newinstance.it/2008/10/24/always-on-getter-and-setters/</link>
		<comments>http://en.newinstance.it/2008/10/24/always-on-getter-and-setters/#comments</comments>
		<pubDate>Fri, 24 Oct 2008 09:37:15 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
				<category><![CDATA[Horror Code]]></category>

		<guid isPermaLink="false">http://en.newinstance.it/2008/10/24/always-on-getter-and-setters/</guid>
		<description><![CDATA[Welcome to anti-refactoring lesson 2. There are painters that paint with pencils or brushes and painter that paints with a bucket. A bucket is very effective if you just want a canvas filled. An example: 1 private String prefix; 2 public String getPrefix(){ 3 return getClass().getPackage().getName(); 4 } 5 public void setPrefix(String prefix) { 6 [...]]]></description>
			<content:encoded><![CDATA[<p><!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic -->Welcome to anti-refactoring lesson 2. </p>
<p>There are painters that paint with pencils or brushes and painter that paints with a bucket. A bucket is very effective if you just want a canvas filled. An example:</p>
<pre class="java"><span class="line_number">1</span><span class="code">    <span class="java_keyword">private</span> String prefix;
<span class="line_number">2</span>    <span class="java_keyword">public</span> String getPrefix<span class="parenthesis">(){</span>
<span class="line_number">3</span>        <span class="java_keyword">return</span> getClass<span class="parenthesis">()</span>.getPackage<span class="parenthesis">()</span>.getName<span class="parenthesis">()</span>;
<span class="line_number">4</span>    <span class="parenthesis">}</span>
<span class="line_number">5</span>    <span class="java_keyword">public</span> <span class="java_primitive_type">void</span> setPrefix<span class="parenthesis">(</span>String prefix<span class="parenthesis">)</span> <span class="parenthesis">{</span>
<span class="line_number">6</span>        <span class="java_keyword">this</span>.prefix = prefix;
<span class="line_number">7</span>    <span class="parenthesis">}</span></span>
</pre>
<p>Neat! I don't even think that an IDE can produce dumb stuff like this: set a value, and ignore it. Remembering the principle of the minimum surprise...</p>
<p>Fortunately Eclipse warned me that prefix is never used; in a complete mess like the one I am getting Eclipse is an invaluable ally. Slowly cleaning up...
<div id="crp_related">
<h4>Related Posts:</h4>
<ul>
<li><a href="http://en.newinstance.it/2008/10/24/the-repetita-juvant-principle/" rel="bookmark" class="crp_title">The Repetita Juvant Principle</a></li>
<li><a href="http://en.newinstance.it/2008/11/04/dynamic-tests-with-junit-3/" rel="bookmark" class="crp_title">Dynamic tests with JUnit 3</a></li>
<li><a href="http://en.newinstance.it/2008/10/22/programmers-like-writing-dumb-code/" rel="bookmark" class="crp_title">Programmers like writing dumb code</a></li>
<li><a href="http://en.newinstance.it/2008/11/22/random-thoughts-about-unchecked-exceptions/" rel="bookmark" class="crp_title">Random thoughts about unchecked exceptions</a></li>
<li><a href="http://en.newinstance.it/2006/11/19/reading-javadocs-from-inside-the-original-zip-file/" rel="bookmark" class="crp_title">Reading Javadocs from inside the original zip file</a></li>
</ul>
</div>
<div class="shr-publisher-330"></div>
<p><!-- Start Shareaholic LikeButtonSetBottom Automatic -->
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2008%2F10%2F24%2Falways-on-getter-and-setters%2F' data-shr_title='Always+on+getter+and+setters'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2008%2F10%2F24%2Falways-on-getter-and-setters%2F' data-shr_title='Always+on+getter+and+setters'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2008%2F10%2F24%2Falways-on-getter-and-setters%2F' data-shr_title='Always+on+getter+and+setters'></a></div>
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<p><!-- End Shareaholic LikeButtonSetBottom Automatic --></p>
]]></content:encoded>
			<wfw:commentRss>http://en.newinstance.it/2008/10/24/always-on-getter-and-setters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programmers like writing dumb code</title>
		<link>http://en.newinstance.it/2008/10/22/programmers-like-writing-dumb-code/</link>
		<comments>http://en.newinstance.it/2008/10/22/programmers-like-writing-dumb-code/#comments</comments>
		<pubDate>Tue, 21 Oct 2008 22:02:58 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
				<category><![CDATA[Horror Code]]></category>

		<guid isPermaLink="false">http://en.newinstance.it/2008/10/22/programmers-like-writing-dumb-code/</guid>
		<description><![CDATA[It is quite fun when you see an extremely verbose code that can be replaced by two or three lines, just removing useless stuff, or using the correct API. But it is much less fun, when an expert makes a huge refactoring on your codebase covering it of useless crap. It happened to me today [...]]]></description>
			<content:encoded><![CDATA[<p><!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic -->It is quite fun when you see an extremely verbose code that can be replaced by two or three lines, just removing useless stuff, or using the correct API. But it is much less fun, when an <em>expert</em> makes a huge <em>refactoring</em> on your codebase covering it of useless crap. It happened to me today (I should say <em>yesterday</em> I just passed the midnight).<br />
On the good side of the coin, I have material to post in my horror code gallery for the next 3 or 4 days.<br />
This is the first masterpiece.</p>
<p>Here is conceptually<sup><a href="#note_329_1">1</a></sup> how the code was, before the <em>expert</em>'s action:</p>
<pre class="java"><span class="line_number"> 1</span><span class="code"><span class="java_keyword">public</span> <span class="java_keyword">class</span> DoSomethingTask<span class="parenthesis">()</span> <span class="parenthesis">{</span>
<span class="line_number"> 2</span>    <span class="comment_line">// private fields</span>
<span class="line_number"> 3</span>
<span class="line_number"> 4</span>    <span class="java_keyword">public</span> DoSomethingTask<span class="parenthesis">(</span>Dependency1 dependency1<span class="parenthesis">)</span> <span class="parenthesis">{</span>
<span class="line_number"> 5</span>        <span class="java_keyword">this</span>.dependency1 = dependency1;
<span class="line_number"> 6</span>        <span class="java_keyword">this</span>.dependency2 = <span class="java_keyword">new</span> Dependency2<span class="parenthesis">(</span>dependency1<span class="parenthesis">)</span>;
<span class="line_number"> 7</span>        <span class="java_keyword">this</span>.dependency3 = <span class="java_keyword">new</span> Dependency3<span class="parenthesis">()</span>;
<span class="line_number"> 8</span>        <span class="comment_line">// ... and so on...</span>
<span class="line_number"> 9</span>    <span class="parenthesis">}</span>
<span class="line_number">10</span><span class="parenthesis">}</span></span>
</pre>
<p>Easy uh? How the <em>expert improved</em> that code?<br />
Simple: he removed constructor arguments, and substituted with setters and getters, then he implemented the "lazy instantiation" (wow! a pattern!).</p>
<p>Here is what he did:</p>
<pre class="java"><span class="line_number"> 1</span><span class="code"><span class="java_keyword">public</span> <span class="java_keyword">class</span> DoSomethingTask<span class="parenthesis">()</span> <span class="parenthesis">{</span>
<span class="line_number"> 2</span>    <span class="comment_line">// private fields</span>
<span class="line_number"> 3</span>
<span class="line_number"> 4</span>    <span class="java_keyword">public</span> DoSomethingTask<span class="parenthesis">()</span> <span class="parenthesis">{</span>
<span class="line_number"> 5</span>        <span class="comment_line">// nothing here</span>
<span class="line_number"> 6</span>    <span class="parenthesis">}</span>
<span class="line_number"> 7</span>
<span class="line_number"> 8</span>    <span class="java_keyword">public</span> <span class="java_primitive_type">void</span> setDependency1<span class="parenthesis">(</span>Dependency1 dependency1<span class="parenthesis">)</span> <span class="parenthesis">{</span>
<span class="line_number"> 9</span>        <span class="java_keyword">this</span>.dependency1 = dependency1;
<span class="line_number">10</span>    <span class="parenthesis">}</span>
<span class="line_number">11</span>
<span class="line_number">12</span>    <span class="java_keyword">public</span> Dependency1 getDependency1<span class="parenthesis">()</span> <span class="parenthesis">{</span>
<span class="line_number">13</span>        <span class="java_keyword">if</span> <span class="parenthesis">(</span>dependency1 == <span class="java_keyword">null</span><span class="parenthesis">)</span>
<span class="line_number">14</span>            dependency1 = Dependency1.getInstance<span class="parenthesis">()</span>;
<span class="line_number">15</span>        <span class="java_keyword">return</span> dependency1;
<span class="line_number">16</span>    <span class="parenthesis">}</span>
<span class="line_number">17</span>
<span class="line_number">18</span>    <span class="java_keyword">public</span> <span class="java_primitive_type">void</span> setDependency2<span class="parenthesis">(</span>Dependency2 dependency2<span class="parenthesis">)</span> <span class="parenthesis">{</span>
<span class="line_number">19</span>        <span class="java_keyword">this</span>.dependency2 = dependency2;
<span class="line_number">20</span>    <span class="parenthesis">}</span>
<span class="line_number">21</span>
<span class="line_number">22</span>    <span class="java_keyword">public</span> Dependency2 getDependency2<span class="parenthesis">()</span> <span class="parenthesis">{</span>
<span class="line_number">23</span>        <span class="java_keyword">if</span> <span class="parenthesis">(</span>dependency2 == <span class="java_keyword">null</span><span class="parenthesis">)</span>
<span class="line_number">24</span>            dependency2 = <span class="java_keyword">new</span> Dependency2<span class="parenthesis">(</span>getDependency1<span class="parenthesis">())</span>;
<span class="line_number">25</span>        <span class="java_keyword">return</span> dependency2;
<span class="line_number">26</span>    <span class="parenthesis">}</span>
<span class="line_number">27</span>
<span class="line_number">28</span>    <span class="java_keyword">public</span> Dependency3 getDependency3<span class="parenthesis">()</span> <span class="parenthesis">{</span>
<span class="line_number">29</span>        <span class="java_keyword">if</span> <span class="parenthesis">(</span>dependency3 == <span class="java_keyword">null</span><span class="parenthesis">)</span>
<span class="line_number">30</span>            dependency3 = <span class="java_keyword">new</span> Dependency3<span class="parenthesis">()</span>;
<span class="line_number">31</span>        <span class="java_keyword">return</span> dependency3;
<span class="line_number">32</span>    <span class="parenthesis">}</span>
<span class="line_number">33</span>
<span class="line_number">34</span>    <span class="java_keyword">public</span> <span class="java_primitive_type">void</span> setDependency3<span class="parenthesis">(</span>Dependency3 dependency3<span class="parenthesis">)</span> <span class="parenthesis">{</span>
<span class="line_number">35</span>        <span class="java_keyword">this</span>.dependency3 = dependency3;
<span class="line_number">36</span>    <span class="parenthesis">}</span>
<span class="line_number">37</span>
<span class="line_number">38</span>    <span class="comment_line">// autopilot-mode=on ... same stuff for every single field I was having in the class, and for every class </span>
<span class="line_number">39</span><span class="parenthesis">}</span></span>
</pre>
<p>Once a colleague asked why he was always providing accessors for all the arguments declared on the constructor. He replied something like: <em>"because when you declare something to the constructor, you are telling the world that the object has those public properties, then you have to provide getter and setters"</em>.  Have you ever heard a bigger one? <a href="http://c2.com/cgi/wiki?EncapsulationDefinition">Encapsulation</a> and <a href="http://c2.com/cgi/wiki?InformationHiding">information hiding</a>... these unknown...<br />
There is people around liking to write complete verbose, useless, dumb and <a href="http://c2.com/cgi/wiki?AccessorsAreEvil">harmful</a> code. Hope for them that they are paid on number of lines of code they write.</p>
<p>Yes, it has been an hard day.</p>
<p><strong>NOTE</strong><br />
<sup><a name="note_329_1">1</a></sup> As I am a contractor, I cannot disclose real code, so I replaced the actual code with conceptually equivalent stuff. BTW, if anybody wants to grab horrific techniques from my horror code gallery, please do at his own risk.
<div id="crp_related">
<h4>Related Posts:</h4>
<ul>
<li><a href="http://en.newinstance.it/2008/10/24/always-on-getter-and-setters/" rel="bookmark" class="crp_title">Always on getter and setters</a></li>
<li><a href="http://en.newinstance.it/2008/10/24/the-repetita-juvant-principle/" rel="bookmark" class="crp_title">The Repetita Juvant Principle</a></li>
<li><a href="http://en.newinstance.it/2008/11/04/dynamic-tests-with-junit-3/" rel="bookmark" class="crp_title">Dynamic tests with JUnit 3</a></li>
<li><a href="http://en.newinstance.it/2008/11/22/random-thoughts-about-unchecked-exceptions/" rel="bookmark" class="crp_title">Random thoughts about unchecked exceptions</a></li>
<li><a href="http://en.newinstance.it/2006/11/19/reading-javadocs-from-inside-the-original-zip-file/" rel="bookmark" class="crp_title">Reading Javadocs from inside the original zip file</a></li>
</ul>
</div>
<div class="shr-publisher-329"></div>
<p><!-- Start Shareaholic LikeButtonSetBottom Automatic -->
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2008%2F10%2F22%2Fprogrammers-like-writing-dumb-code%2F' data-shr_title='Programmers+like+writing+dumb+code'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2008%2F10%2F22%2Fprogrammers-like-writing-dumb-code%2F' data-shr_title='Programmers+like+writing+dumb+code'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2008%2F10%2F22%2Fprogrammers-like-writing-dumb-code%2F' data-shr_title='Programmers+like+writing+dumb+code'></a></div>
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<p><!-- End Shareaholic LikeButtonSetBottom Automatic --></p>
]]></content:encoded>
			<wfw:commentRss>http://en.newinstance.it/2008/10/22/programmers-like-writing-dumb-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Strings in switch statements</title>
		<link>http://en.newinstance.it/2008/06/28/strings-in-switch-statements/</link>
		<comments>http://en.newinstance.it/2008/06/28/strings-in-switch-statements/#comments</comments>
		<pubDate>Fri, 27 Jun 2008 22:34:13 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
				<category><![CDATA[Horror Code]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://it.newinstance.it/2008/06/28/strings-in-switch-statements/</guid>
		<description><![CDATA[Apparently, with JDK 7 we will have Strings in switch statements. I got a SCPJ certification long time back, but if someone asks me to write a switch statement in a job interview today, I could probably fail: I begun writing Java code in 2000, and I bet I used switch statement six or seven [...]]]></description>
			<content:encoded><![CDATA[<p><!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic -->Apparently, with JDK 7 we will have <a href="http://today.java.net/pub/a/today/2007/08/09/looking-ahead-to-java-7.html">Strings in switch statements</a>. I got a SCPJ certification long time back, but if someone asks me to write a switch statement in a job interview today, I could probably fail: I begun writing Java code in 2000, and I bet I used switch statement six or seven times since then. Half of that times at the beginning for sure, and probably always I should have avoided that in favor of making better object oriented design. </p>
<p>Bad programmer have been able to use Strings in switch statements since the beginning: necessity sharpen sb's wits.  </p>
<p>I found a nice pearl regarding the switch on the Strings. Viewer Discretion is Advised!<br />
Look at this:</p>
<pre class="java"><span class="line_number"> 1</span><span class="code"><span class="java_keyword">switch</span><span class="parenthesis">(</span>_Temp.getLocalName<span class="parenthesis">()</span>.toLowerCase<span class="parenthesis">()</span>.hashCode<span class="parenthesis">())</span>
<span class="line_number"> 2</span><span class="parenthesis">{</span>
<span class="line_number"> 3</span>  <span class="java_keyword">case</span> -<span class="numeric_constant">84691548</span>:  <span class="comment_line">// = &quot;get-transfer-url&quot;.toLowerCase().hashCode()</span>
<span class="line_number"> 4</span>  <span class="parenthesis">{</span>
<span class="line_number"> 5</span>    _getTransferUrl =  _Temp.getFirstChild<span class="parenthesis">()</span>.getNodeValue<span class="parenthesis">()</span>.trim<span class="parenthesis">()</span> ;
<span class="line_number"> 6</span>    <span class="java_keyword">break</span>;
<span class="line_number"> 7</span>  <span class="parenthesis">}</span>
<span class="line_number"> 8</span>  <span class="java_keyword">case</span> <span class="numeric_constant">457922078</span>:  <span class="comment_line">// = &quot;is-authorized&quot;.toLowerCase().hashCode()</span>
<span class="line_number"> 9</span>  <span class="parenthesis">{</span>
<span class="line_number">10</span>    _isAuthorized = Boolean.valueOf<span class="parenthesis">(</span> _Temp.getFirstChild<span class="parenthesis">()</span>.getNodeValue<span class="parenthesis">()</span>.trim<span class="parenthesis">()</span> <span class="parenthesis">)</span>.booleanValue<span class="parenthesis">()</span>;
<span class="line_number">11</span>    <span class="java_keyword">break</span>;
<span class="line_number">12</span>  <span class="parenthesis">}</span>
<span class="line_number">13</span>  <span class="java_keyword">case</span> <span class="numeric_constant">998201997</span>:  <span class="comment_line">// = &quot;is-charged&quot;.toLowerCase().hashCode()</span>
<span class="line_number">14</span>  <span class="parenthesis">{</span>
<span class="line_number">15</span>    _isCharged = Boolean.valueOf<span class="parenthesis">(</span> _Temp.getFirstChild<span class="parenthesis">()</span>.getNodeValue<span class="parenthesis">()</span>.trim<span class="parenthesis">()</span> <span class="parenthesis">)</span>.booleanValue<span class="parenthesis">()</span>;
<span class="line_number">16</span>    <span class="java_keyword">break</span>;
<span class="line_number">17</span>  <span class="parenthesis">}</span>
<span class="line_number">18</span>  <span class="java_keyword">case</span> -<span class="numeric_constant">2085709659</span>:  <span class="comment_line">// = &quot;get-resource&quot;.toLowerCase().hashCode()</span>
<span class="line_number">19</span>  <span class="parenthesis">{</span>
<span class="line_number">20</span>    _getResource = <span class="java_keyword">new</span> ChargingResource<span class="parenthesis">(</span>_Temp<span class="parenthesis">)</span>;
<span class="line_number">21</span>    <span class="java_keyword">break</span>;
<span class="line_number">22</span>  <span class="parenthesis">}</span>
<span class="line_number">23</span>  <span class="comment_line">//... continues for about 500 lines more...</span>
<span class="line_number">24</span><span class="parenthesis">}</span> </span>
</pre>
<p>Hoping Java will never change the hash code implementation on the Strings, as actually happened before for other wrapper classes.<br />
At least the author could have used the string itself in place of the comment... I imagine the programmer hard coding the hash code in the switch to boost performance. Very smart...</p>
<pre class="java"><span class="line_number">1</span><span class="code"><span class="java_keyword">switch</span><span class="parenthesis">(</span>_Temp.getLocalName<span class="parenthesis">()</span>.toLowerCase<span class="parenthesis">()</span>.hashCode<span class="parenthesis">())</span>
<span class="line_number">2</span><span class="parenthesis">{</span>
<span class="line_number">3</span>  <span class="java_keyword">case</span> <span class="string_constant">&quot;get-transfer-url&quot;</span>.toLowerCase<span class="parenthesis">()</span>.hashCode<span class="parenthesis">()</span> :
<span class="line_number">4</span>  <span class="parenthesis">{</span>
<span class="line_number">5</span>    _getTransferUrl =  _Temp.getFirstChild<span class="parenthesis">()</span>.getNodeValue<span class="parenthesis">()</span>.trim<span class="parenthesis">()</span> ;
<span class="line_number">6</span>    <span class="java_keyword">break</span>;
<span class="line_number">7</span>  <span class="parenthesis">}</span>
<span class="line_number">8</span>
<span class="line_number">9</span><span class="parenthesis">}</span> </span>
</pre>
<p>Still horrible, and designed to fail (hash codes can conflict). </p>
<p>Maybe I am beginning to become a conservative dinosaur, but since JDK 5 (and maybe 1.4) I don't see the reason of many of the "improvements" that have been included and will be included in the Java language. Simplicity made of Java a success. I see every day pile of code written by "experienced" developers capable to overpatternize banalities and still unable to handle properly an exception. What's the matter of adding more complexity and features? Also including harmful ones like String in switch statement... Personally I think that the switch statement should be deprecated <em>tout cour</em>. </p>
<div id="crp_related">
<h4>Related Posts:</h4>
<ul>
<li><a href="http://en.newinstance.it/2008/10/24/always-on-getter-and-setters/" rel="bookmark" class="crp_title">Always on getter and setters</a></li>
<li><a href="http://en.newinstance.it/2008/11/04/dynamic-tests-with-junit-3/" rel="bookmark" class="crp_title">Dynamic tests with JUnit 3</a></li>
<li><a href="http://en.newinstance.it/2008/10/24/the-repetita-juvant-principle/" rel="bookmark" class="crp_title">The Repetita Juvant Principle</a></li>
<li><a href="http://en.newinstance.it/2008/11/22/random-thoughts-about-unchecked-exceptions/" rel="bookmark" class="crp_title">Random thoughts about unchecked exceptions</a></li>
<li><a href="http://en.newinstance.it/2008/10/22/programmers-like-writing-dumb-code/" rel="bookmark" class="crp_title">Programmers like writing dumb code</a></li>
</ul>
</div>
<div class="shr-publisher-300"></div>
<p><!-- Start Shareaholic LikeButtonSetBottom Automatic -->
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2008%2F06%2F28%2Fstrings-in-switch-statements%2F' data-shr_title='Strings+in+switch+statements'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2008%2F06%2F28%2Fstrings-in-switch-statements%2F' data-shr_title='Strings+in+switch+statements'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2008%2F06%2F28%2Fstrings-in-switch-statements%2F' data-shr_title='Strings+in+switch+statements'></a></div>
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<p><!-- End Shareaholic LikeButtonSetBottom Automatic --></p>
]]></content:encoded>
			<wfw:commentRss>http://en.newinstance.it/2008/06/28/strings-in-switch-statements/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Unit Testing internal object state</title>
		<link>http://en.newinstance.it/2005/12/07/unit-testing-internal-object-state/</link>
		<comments>http://en.newinstance.it/2005/12/07/unit-testing-internal-object-state/#comments</comments>
		<pubDate>Tue, 06 Dec 2005 23:59:59 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
				<category><![CDATA[Horror Code]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://it.newinstance.it/1970/01/01/unit-testing-internal-object-state/</guid>
		<description><![CDATA[I don&#8217;t know what XPers whould say about this, but I found it useful. Maybe someone could say: if you are not able to test something of your API, maybe you&#8217;ve badly designed your components&#8230; or: you should&#8217;n test this, because this is internal specifics of your object and you don&#8217;t have to know or [...]]]></description>
			<content:encoded><![CDATA[<p><!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic -->
<p>I don&#8217;t know what XPers whould say about this, but I found it useful. Maybe someone could say: if you are not able to test something of your API, maybe you&#8217;ve badly designed your components&#8230; or: you should&#8217;n test this, because this is internal specifics of your object and you don&#8217;t have to know or test it: if you change internal implementation your test will fail. or&#8230; you need this &#8216;xyz&#8217; test pattern. or&#8230; I don&#8217;t know. This is why following code has been posted in my &#8216;horror code&#8217; category.<br />Here&#8217;s the base class I used to implement some junit TestCases that need to access to internal details of my objects:</p>
<pre style="height: 200px">/**
 * $Id: InternalAccessorTestCase.java 77 2005-12-06 14:46:42Z luigi $
 */
package it.newinstance.test.util;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import junit.framework.TestCase;

/**
 * Base class for TestCases that need to access private fields and methods
 */
public abstract class InternalAccessorTestCase extends TestCase {

    protected static Object getFieldValue(Object o, String fieldName) {
        try {
            return getField(o.getClass(), fieldName).get(o);
        } catch (Exception x) {
            throw new RuntimeException(x);
        }
    }

    protected static Object invoke(Object o, String methodName, Object[] args,
            Class[] types) {
        try {
            return getMethod(o.getClass(), methodName, types).invoke(o, args);
        } catch (Exception x) {
            throw new RuntimeException(x);
        }
    }

    private static Field getField(Class clazz, String fieldName)
            throws NoSuchFieldException {
        try {
            Field f = clazz.getDeclaredField(fieldName);
            f.setAccessible(true);
            return f;
        } catch (SecurityException e) {
            throw new RuntimeException(e);
        } catch (NoSuchFieldException e) {
            if (clazz == Object.class)
                throw e;
            return getField(clazz.getSuperclass(), fieldName);
        }
    }

    private static Method getMethod(Class clazz, String methodName,
            Class[] types) throws NoSuchMethodException {
        try {
            Method m = clazz.getDeclaredMethod(methodName, types);
            m.setAccessible(true);
            return m;
        } catch (SecurityException x) {
            throw new RuntimeException(x);
        } catch (NoSuchMethodException x) {
            if (clazz == Object.class)
                throw x;
            return getMethod(clazz.getSuperclass(), methodName, types);
        }
    }
}
</pre>
<p>I needed to check the internal state of an object, that does some job, but does not expose anything that can be tested. I just parse some xml and instantiate an object with its components, then I needed to test that the composition has been done as I expect.<br />This is how my test appears:</p>
<pre style="height: 200px">/**
 * $Id: ParserTest.java 81 2005-12-06 23:08:42Z luigi $
 */
package it.newinstance.test.watchdog.xml;

import java.util.List;

public class ParserTest extends InternalAccessorTestCase {

    public void testServerWithOneMonitorAndOneListener() throws Exception {...}

    public void testServerWithMonitorWithParametersAndNullListener()
            throws Exception {
        String xmlPath = getCurrentPath()
                + "/ServerWithMonitorWithParametersAndNullListener.xml";
        Server s = new Parser(Util.getStream(xmlPath)).parse();
        assertNotNull(s);
        List monitorEntries = (List) getFieldValue(s, "monitorEntries");
        assertTrue(monitorEntries.size() == 1);
        for (Object monitorEntry : monitorEntries) {
            MockMonitorWithParameters m = (MockMonitorWithParameters)
                getFieldValue(monitorEntry, "monitor");
            assertEquals("thisIsATest", m.getStringValue());
            assertEquals(10, m.getIntValue());
            assertEquals(5.5, m.getDoubleValue(), 0.0D);
            assertEquals(true, m.isBooleanValueTrue());
            assertEquals(false, m.isBooleanValueFalse());
            assertEquals(new Integer(15), m.getWrapperIntegerValue());
            assertEquals(new Double(3.14D), m.getWrapperDoubleValue(), 0.0D);
            assertEquals(Boolean.TRUE, m.getWrapperBooleanValueTrue());
            assertEquals(Boolean.FALSE, m.getWrapperBooleanValueFalse());
            List listeners = (List) getFieldValue(m, "listeners");
            assertTrue(listeners.size() == 1);
            for (Object object : listeners) {
                Listener listener = (Listener) object;
                assertEquals("MyListenerName", listener.getName());
            }
        }
    }

    private String getCurrentPath() {
        return getClass().getPackage().getName().replace('.', '/');
    }
}
</pre>
<p>Calls to getFieldValue utility methods, makes access to private member variable of object(s) to be tested. I made two methods: getFieldValue to access private field of objects, and invoke, that is able to invoke private methods of my test objects.</p>
<p>Maybe this code is horror enough (?): recently I am neglecting this blog, and also posting so few about code&#8230; I&#8217;m doing not much interresting coding, but I enjoy what I read on jroller and other blogs&#8230;</p>
<div id="crp_related">
<h4>Related Posts:</h4>
<ul>
<li><a href="http://en.newinstance.it/2009/03/27/mocking-jndi/" rel="bookmark" class="crp_title">Mocking JNDI</a></li>
<li><a href="http://en.newinstance.it/2008/11/04/dynamic-tests-with-junit-3/" rel="bookmark" class="crp_title">Dynamic tests with JUnit 3</a></li>
<li><a href="http://en.newinstance.it/2006/10/19/automatic-transaction-management-with-pojos/" rel="bookmark" class="crp_title">Automatic transaction management with POJOs</a></li>
<li><a href="http://en.newinstance.it/2008/11/17/throwing-undeclared-checked-exceptions/" rel="bookmark" class="crp_title">Throwing undeclared checked exceptions</a></li>
<li><a href="http://en.newinstance.it/2008/06/24/null-is-throwable/" rel="bookmark" class="crp_title">Null is throwable</a></li>
</ul>
</div>
<div class="shr-publisher-126"></div>
<p><!-- Start Shareaholic LikeButtonSetBottom Automatic -->
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2005%2F12%2F07%2Funit-testing-internal-object-state%2F' data-shr_title='Unit+Testing+internal+object+state'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2005%2F12%2F07%2Funit-testing-internal-object-state%2F' data-shr_title='Unit+Testing+internal+object+state'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2005%2F12%2F07%2Funit-testing-internal-object-state%2F' data-shr_title='Unit+Testing+internal+object+state'></a></div>
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<p><!-- End Shareaholic LikeButtonSetBottom Automatic --></p>
]]></content:encoded>
			<wfw:commentRss>http://en.newinstance.it/2005/12/07/unit-testing-internal-object-state/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Infamous programming errors on curly braced {blocks}</title>
		<link>http://en.newinstance.it/2005/06/11/infamous-programming-errors-on-curly-braced-blocks/</link>
		<comments>http://en.newinstance.it/2005/06/11/infamous-programming-errors-on-curly-braced-blocks/#comments</comments>
		<pubDate>Sat, 11 Jun 2005 07:44:53 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
				<category><![CDATA[Horror Code]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://it.newinstance.it/2005/06/11/infamous-programming-errors-on-curly-braced-blocks/</guid>
		<description><![CDATA[It was a late evening when I fall in buggy a code like this: Destination newDestination = null; if (! originalDestination.getId().equals(getDestinationId())); { newDestination = context.loadDestination(getDestinationId()); prefix.setDestination(newDestination); } context.save(prefix); if (newDestination != null) { newDestination.addPrefix(prefix); originalDestination.removePrefix(prefix); context.save(originalDestination); context.save(newDestination); } When the first if block is true, the second one will also be true, because the line [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>
It was a late evening when I fall in buggy a code like this:
</p>

<pre>Destination newDestination <span style="color: rgb(128, 128, 48);">=</span> <span style="color: rgb(128, 0, 0); font-weight: bold;">null</span><span style="color: rgb(128, 0, 128);">;</span>
<span style="color: rgb(128, 0, 0); font-weight: bold;">if</span> <span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(128, 128, 48);">!</span> originalDestination<span style="color: rgb(128, 128, 48);">.</span>getId<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">.</span>equals<span style="color: rgb(128, 128, 48);">(</span>getDestinationId<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 0, 128);">;</span>
<span style="color: rgb(128, 0, 128);">{</span>
    newDestination <span style="color: rgb(128, 128, 48);">=</span> context<span style="color: rgb(128, 128, 48);">.</span>loadDestination<span style="color: rgb(128, 128, 48);">(</span>getDestinationId<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 0, 128);">;</span>
    prefix<span style="color: rgb(128, 128, 48);">.</span>setDestination<span style="color: rgb(128, 128, 48);">(</span>newDestination<span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 0, 128);">;</span>
<span style="color: rgb(128, 0, 128);">}</span>
context<span style="color: rgb(128, 128, 48);">.</span>save<span style="color: rgb(128, 128, 48);">(</span>prefix<span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 0, 128);">;</span>
<span style="color: rgb(128, 0, 0); font-weight: bold;">if</span> <span style="color: rgb(128, 128, 48);">(</span>newDestination <span style="color: rgb(128, 128, 48);">!</span><span style="color: rgb(128, 128, 48);">=</span> <span style="color: rgb(128, 0, 0); font-weight: bold;">null</span><span style="color: rgb(128, 128, 48);">)</span>
<span style="color: rgb(128, 0, 128);">{</span>
    newDestination<span style="color: rgb(128, 128, 48);">.</span>addPrefix<span style="color: rgb(128, 128, 48);">(</span>prefix<span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 0, 128);">;</span>
    originalDestination<span style="color: rgb(128, 128, 48);">.</span>removePrefix<span style="color: rgb(128, 128, 48);">(</span>prefix<span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 0, 128);">;</span>
    context<span style="color: rgb(128, 128, 48);">.</span>save<span style="color: rgb(128, 128, 48);">(</span>originalDestination<span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 0, 128);">;</span>
    context<span style="color: rgb(128, 128, 48);">.</span>save<span style="color: rgb(128, 128, 48);">(</span>newDestination<span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 0, 128);">;</span>
<span style="color: rgb(128, 0, 128);">}</span>
</pre>

<p>
When the first if block is true, the second one will also be true, because the line at 4 will force newDestinatio to be not-null. The strange thing was that the second if-block was always executed, so I started to do step-by-step debugging. Working with cglib-proxied objects (hibernate) I was starting to think on some bug somewhere in the framework. Wrong! The bug is there and was under my nose but nicely hidden. Can you see it?<br />
Check the end of line 2, at the end of the if condition... there's a ";" so that the first if will execute an empty statement, and the block under the if will ever been executed. It was so  surprising checking internal values thru the debugger and then see the if being executed even if the condition was false! 
</p>

<p>
I was surprised tha Eclipse does not pointed me over the code inconsistency (a warning). If you enable warning on empty statements (Preferences-&gt;Java-&gt;Compiler-&gt;Errors/Warning-&gt;Potential Programming Problems-&gt;Empty Statements), you could notice easier errors like this. But there's no way to define a warning of  blocks {} without a previous construct (if/while/for...). Even if sometime correctly used, empty blocks are always ugly (i.e. for(int i=0; i&gt;x; doSomething(i++)); ugly!). So I enabled this as an error, in eclipse compiler. Would be nice to be warned on instruction blocks without a construct on top (like the range of lines between 3 and 6).  
</p><div id="crp_related"><h4>Related Posts:</h4><ul><li><a href="http://en.newinstance.it/2005/06/17/adding-hidden-fields-to-a-form/" rel="bookmark" class="crp_title">Adding hidden fields to a Form</a></li><li><a href="http://en.newinstance.it/2005/07/11/webwork-package-configuration-problem/" rel="bookmark" class="crp_title">Webwork Package Configuration Problem</a></li><li><a href="http://en.newinstance.it/2008/10/24/always-on-getter-and-setters/" rel="bookmark" class="crp_title">Always on getter and setters</a></li><li><a href="http://en.newinstance.it/2005/07/11/hibernate-and-database-views/" rel="bookmark" class="crp_title">Hibernate and Database Views</a></li><li><a href="http://en.newinstance.it/2009/03/05/ant-macrodefs/" rel="bookmark" class="crp_title">Ant macrodefs</a></li></ul></div><div class="shr-publisher-170"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2005%2F06%2F11%2Finfamous-programming-errors-on-curly-braced-blocks%2F' data-shr_title='Infamous+programming+errors+on+curly+braced+%7Bblocks%7D'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2005%2F06%2F11%2Finfamous-programming-errors-on-curly-braced-blocks%2F' data-shr_title='Infamous+programming+errors+on+curly+braced+%7Bblocks%7D'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2005%2F06%2F11%2Finfamous-programming-errors-on-curly-braced-blocks%2F' data-shr_title='Infamous+programming+errors+on+curly+braced+%7Bblocks%7D'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://en.newinstance.it/2005/06/11/infamous-programming-errors-on-curly-braced-blocks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>StringBuffer considered harmuful</title>
		<link>http://en.newinstance.it/2005/06/07/stringbuffer-considered-harmuful/</link>
		<comments>http://en.newinstance.it/2005/06/07/stringbuffer-considered-harmuful/#comments</comments>
		<pubDate>Tue, 07 Jun 2005 14:48:12 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
				<category><![CDATA[Horror Code]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://it.newinstance.it/2005/06/07/stringbuffer-considered-harmuful/</guid>
		<description><![CDATA[That building Strings using StringBuffer (and in Java 5 StringBuilder) is much faster and less memory expensive than using String concatenation, is not a secret. But porting this concept to extremes, you can fall in coding conventions that mandate to never use String concatenation. And you can face hibernate queries like this: 1String alias = [...]]]></description>
			<content:encoded><![CDATA[<p><!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic -->That building Strings using StringBuffer (and in Java 5 StringBuilder) is much faster and less memory expensive than using String concatenation, is not a secret.<br />
But porting this concept to extremes, you can fall in coding conventions that mandate to never use String concatenation. And you can face hibernate queries like this:</p>
<pre class="java"><span class="line_number"> 1</span><span class="code">String alias = <span class="string_constant">&quot;cd&quot;</span>;
<span class="line_number"> 2</span>
<span class="line_number"> 3</span>StringBuffer expression = <span class="java_keyword">new</span> StringBuffer<span class="parenthesis">(</span><span class="string_constant">&quot;select &quot;</span><span class="parenthesis">)</span>;
<span class="line_number"> 4</span>expression.append<span class="parenthesis">(</span>alias<span class="parenthesis">)</span>.append<span class="parenthesis">(</span><span class="string_constant">&quot;.account.name, &quot;</span><span class="parenthesis">)</span>;
<span class="line_number"> 5</span>expression.append<span class="parenthesis">(</span>alias<span class="parenthesis">)</span>.append<span class="parenthesis">(</span><span class="string_constant">&quot;.startDate, &quot;</span><span class="parenthesis">)</span>;
<span class="line_number"> 6</span>expression.append<span class="parenthesis">(</span><span class="string_constant">&quot;sum(&quot;</span><span class="parenthesis">)</span>.append<span class="parenthesis">(</span>alias<span class="parenthesis">)</span>.append<span class="parenthesis">(</span><span class="string_constant">&quot;.duration), &quot;</span><span class="parenthesis">)</span>;
<span class="line_number"> 7</span>expression.append<span class="parenthesis">(</span><span class="string_constant">&quot;sum(&quot;</span><span class="parenthesis">)</span>.append<span class="parenthesis">(</span>alias<span class="parenthesis">)</span>.append<span class="parenthesis">(</span><span class="string_constant">&quot;.cost), &quot;</span><span class="parenthesis">)</span>;
<span class="line_number"> 8</span>expression.append<span class="parenthesis">(</span>alias<span class="parenthesis">)</span>.append<span class="parenthesis">(</span><span class="string_constant">&quot;.account.id from &quot;</span><span class="parenthesis">)</span>;
<span class="line_number"> 9</span>expression.append<span class="parenthesis">(</span>Test.<span class="java_keyword">class</span>.getName<span class="parenthesis">())</span>.append<span class="parenthesis">(</span><span class="string_constant">&quot; as &quot;</span><span class="parenthesis">)</span>.append<span class="parenthesis">(</span>alias<span class="parenthesis">)</span>;
<span class="line_number">10</span>expression.append<span class="parenthesis">(</span><span class="string_constant">&quot; order by &quot;</span><span class="parenthesis">)</span>.append<span class="parenthesis">(</span>alias<span class="parenthesis">)</span>.append<span class="parenthesis">(</span><span class="string_constant">&quot;.startDate desc &quot;</span><span class="parenthesis">)</span>;
<span class="line_number">11</span>
<span class="line_number">12</span>String result = expression.toString<span class="parenthesis">()</span>;
<span class="line_number">13</span><span class="comment_line">// hibernate.executeQuery(...result...);</span>
</pre>
<p>Cool! Only real programmers can read it, isn&#8217;t that? ]:)<br />
You can imagine, that I love to write code this way&#8230; Jokes apart, imagine the time wasted beeing caught executing wrong queries and debugging this!<br />
I tried to discuss this rule, but no-way&#8230; being a contractor, I always have to surrender to major forces :-), and this costs me pains. But at least this time we&#8217;ve discussed (a little, and here&#8217;s my rant). So the code it&#8217;s there. Fortunately in Hibernate 3.x we use Criterion and Projection APIs, so wrinting this kind of code is nomore in my task list. Few!<br />
But going back at that time, you may think that a code like this below is easier to read but slower to execute:</p>
<pre class="java"><span class="line_number"> 1</span><span class="code">String expression =
<span class="line_number"> 2</span>    <span class="string_constant">&quot;select &quot;</span> +
<span class="line_number"> 3</span>        <span class="string_constant">&quot;cd.account.name, &quot;</span> +
<span class="line_number"> 4</span>        <span class="string_constant">&quot;cd.startDate, &quot;</span> +
<span class="line_number"> 5</span>        <span class="string_constant">&quot;sum(cd.duration), &quot;</span> +
<span class="line_number"> 6</span>        <span class="string_constant">&quot;sum(cd.cost), &quot;</span> +
<span class="line_number"> 7</span>        <span class="string_constant">&quot;cd.account.id &quot;</span> +
<span class="line_number"> 8</span>    <span class="string_constant">&quot;from &quot;</span> +
<span class="line_number"> 9</span>        Test.<span class="java_keyword">class</span>.getName<span class="parenthesis">()</span> +
<span class="line_number">10</span>        <span class="string_constant">&quot; as cd &quot;</span> + <span class="string_constant">&quot;order by &quot;</span> +
<span class="line_number">11</span>        <span class="string_constant">&quot;cd.startDate desc&quot;</span>;
<span class="line_number">12</span>String result = expression;
<span class="line_number">13</span><span class="comment_line">// hibernate.executeQuery(...result...);</span>
</pre>
<p>If you think that it&#8217;s slower, you are wrong! Compilers are there to optimize code. String concatenations is made using StringBuffers by the compiler. The compiler can also inline string constants in a single one. Here&#8217;s an example on how the compiler can arrange our previous code:</p>
<pre class="java"><span class="line_number">1</span><span class="code">String expression = <span class="parenthesis">(</span><span class="java_keyword">new</span> StringBuffer<span class="parenthesis">(</span><span class="string_constant">&quot;select cd.account.name, cd.startDate, sum(cd.duration), sum(cd.cost), cd.account.id from &quot;</span><span class="parenthesis">))</span>.append<span class="parenthesis">(</span>Test.getName<span class="parenthesis">())</span>.append<span class="parenthesis">(</span><span class="string_constant">&quot; as cd &quot;</span><span class="parenthesis">)</span>.append<span class="parenthesis">(</span><span class="string_constant">&quot;order by &quot;</span><span class="parenthesis">)</span>.append<span class="parenthesis">(</span><span class="string_constant">&quot;cd.startDate desc&quot;</span><span class="parenthesis">)</span>.toString<span class="parenthesis">()</span>;</span>
</pre>
<p>I&#8217;ve made a little class to compare performance between StringBuffers and String Concatenations for methods building queries like this.<br />
Here&#8217;s the code (results follow)</p>
<pre class="java"><span class="line_number"> 1</span><span class="code"><span class="java_keyword">public</span> <span class="java_keyword">class</span> Test <span class="parenthesis">{</span>
<span class="line_number"> 2</span>    <span class="java_keyword">public</span> <span class="java_keyword">interface</span> Repeatable <span class="parenthesis">{</span>
<span class="line_number"> 3</span>        <span class="java_primitive_type">void</span> iteration<span class="parenthesis">(</span><span class="java_primitive_type">long</span> loopId<span class="parenthesis">)</span>;
<span class="line_number"> 4</span>    <span class="parenthesis">}</span>
<span class="line_number"> 5</span>
<span class="line_number"> 6</span>    <span class="java_keyword">public</span> <span class="java_keyword">static</span> <span class="java_primitive_type">long</span> repeat<span class="parenthesis">(</span><span class="java_primitive_type">int</span> times, Repeatable repeatable<span class="parenthesis">)</span> <span class="parenthesis">{</span>
<span class="line_number"> 7</span>        <span class="java_primitive_type">long</span> initial = System.currentTimeMillis<span class="parenthesis">()</span>;
<span class="line_number"> 8</span>        <span class="java_keyword">for</span> <span class="parenthesis">(</span><span class="java_primitive_type">long</span> c = <span class="numeric_constant">1</span>; c &lt;= times; c++<span class="parenthesis">)</span>
<span class="line_number"> 9</span>            repeatable.iteration<span class="parenthesis">(</span>c<span class="parenthesis">)</span>;
<span class="line_number">10</span>        <span class="java_primitive_type">long</span> elapsed = System.currentTimeMillis<span class="parenthesis">()</span> - initial;
<span class="line_number">11</span>        <span class="java_keyword">return</span> elapsed;
<span class="line_number">12</span>    <span class="parenthesis">}</span>
<span class="line_number">13</span>
<span class="line_number">14</span>    <span class="java_keyword">private</span> <span class="java_keyword">static</span> Repeatable stringBufferTest = <span class="java_keyword">new</span> Repeatable<span class="parenthesis">()</span> <span class="parenthesis">{</span>
<span class="line_number">15</span>        <span class="java_keyword">public</span> <span class="java_primitive_type">void</span> iteration<span class="parenthesis">(</span><span class="java_primitive_type">long</span> loopId<span class="parenthesis">)</span> <span class="parenthesis">{</span>
<span class="line_number">16</span>            String alias = <span class="string_constant">&quot;cd&quot;</span>;
<span class="line_number">17</span>            StringBuffer expression = <span class="java_keyword">new</span> StringBuffer<span class="parenthesis">(</span><span class="string_constant">&quot;select &quot;</span><span class="parenthesis">)</span>;
<span class="line_number">18</span>            expression.append<span class="parenthesis">(</span>alias<span class="parenthesis">)</span>.append<span class="parenthesis">(</span><span class="string_constant">&quot;.account.name, &quot;</span><span class="parenthesis">)</span>;
<span class="line_number">19</span>            expression.append<span class="parenthesis">(</span>alias<span class="parenthesis">)</span>.append<span class="parenthesis">(</span><span class="string_constant">&quot;.startDate, &quot;</span><span class="parenthesis">)</span>;
<span class="line_number">20</span>            expression.append<span class="parenthesis">(</span><span class="string_constant">&quot;sum(&quot;</span><span class="parenthesis">)</span>.append<span class="parenthesis">(</span>alias<span class="parenthesis">)</span>.append<span class="parenthesis">(</span><span class="string_constant">&quot;.duration), &quot;</span><span class="parenthesis">)</span>;
<span class="line_number">21</span>            expression.append<span class="parenthesis">(</span><span class="string_constant">&quot;sum(&quot;</span><span class="parenthesis">)</span>.append<span class="parenthesis">(</span>alias<span class="parenthesis">)</span>.append<span class="parenthesis">(</span><span class="string_constant">&quot;.cost), &quot;</span><span class="parenthesis">)</span>;
<span class="line_number">22</span>            expression.append<span class="parenthesis">(</span>alias<span class="parenthesis">)</span>.append<span class="parenthesis">(</span><span class="string_constant">&quot;.account.id from &quot;</span><span class="parenthesis">)</span>;
<span class="line_number">23</span>            expression.append<span class="parenthesis">(</span>Test.<span class="java_keyword">class</span>.getName<span class="parenthesis">())</span>.append<span class="parenthesis">(</span><span class="string_constant">&quot; as &quot;</span><span class="parenthesis">)</span>.append<span class="parenthesis">(</span>alias<span class="parenthesis">)</span>;
<span class="line_number">24</span>            expression.append<span class="parenthesis">(</span><span class="string_constant">&quot; order by &quot;</span><span class="parenthesis">)</span>.append<span class="parenthesis">(</span>alias<span class="parenthesis">)</span>.append<span class="parenthesis">(</span><span class="string_constant">&quot;.startDate desc &quot;</span><span class="parenthesis">)</span>;
<span class="line_number">25</span>            String result = expression.toString<span class="parenthesis">()</span>;
<span class="line_number">26</span>        <span class="parenthesis">}</span>
<span class="line_number">27</span>    <span class="parenthesis">}</span>;
<span class="line_number">28</span>
<span class="line_number">29</span>    <span class="java_keyword">private</span> <span class="java_keyword">static</span> Repeatable stringConcatenationTest = <span class="java_keyword">new</span> Repeatable<span class="parenthesis">()</span> <span class="parenthesis">{</span>
<span class="line_number">30</span>        <span class="java_keyword">public</span> <span class="java_primitive_type">void</span> iteration<span class="parenthesis">(</span><span class="java_primitive_type">long</span> loopId<span class="parenthesis">)</span> <span class="parenthesis">{</span>
<span class="line_number">31</span>            String expression =
<span class="line_number">32</span>                <span class="string_constant">&quot;select &quot;</span> +
<span class="line_number">33</span>                    <span class="string_constant">&quot;cd.account.name, &quot;</span> +
<span class="line_number">34</span>                    <span class="string_constant">&quot;cd.startDate, &quot;</span> +
<span class="line_number">35</span>                    <span class="string_constant">&quot;sum(cd.duration), &quot;</span> +
<span class="line_number">36</span>                    <span class="string_constant">&quot;sum(cd.cost), &quot;</span> +
<span class="line_number">37</span>                    <span class="string_constant">&quot;cd.account.id &quot;</span> +
<span class="line_number">38</span>                <span class="string_constant">&quot;from &quot;</span> +
<span class="line_number">39</span>                    Test.<span class="java_keyword">class</span>.getName<span class="parenthesis">()</span> +
<span class="line_number">40</span>                    <span class="string_constant">&quot; as cd &quot;</span> + <span class="string_constant">&quot;order by &quot;</span> +
<span class="line_number">41</span>                    <span class="string_constant">&quot;cd.startDate desc&quot;</span>;
<span class="line_number">42</span>            String result = expression;
<span class="line_number">43</span>        <span class="parenthesis">}</span>
<span class="line_number">44</span>    <span class="parenthesis">}</span>;
<span class="line_number">45</span>
<span class="line_number">46</span>    <span class="java_keyword">public</span> <span class="java_keyword">static</span> <span class="java_primitive_type">void</span> main<span class="parenthesis">(</span>String<span class="parenthesis">[]</span> args<span class="parenthesis">)</span> <span class="parenthesis">{</span>
<span class="line_number">47</span>        <span class="java_keyword">for</span> <span class="parenthesis">(</span><span class="java_primitive_type">int</span> loopCount = <span class="numeric_constant">1</span>; loopCount &lt;= <span class="numeric_constant">5</span>; loopCount++<span class="parenthesis">)</span> <span class="parenthesis">{</span>
<span class="line_number">48</span>            <span class="java_primitive_type">int</span> times = <span class="numeric_constant">1000000</span>;
<span class="line_number">49</span>            <span class="java_primitive_type">long</span> stringBuffElapsed, stringConcatElapsed;
<span class="line_number">50</span>
<span class="line_number">51</span>            stringBuffElapsed = repeat<span class="parenthesis">(</span>times, stringBufferTest<span class="parenthesis">)</span>;
<span class="line_number">52</span>            stringConcatElapsed = repeat<span class="parenthesis">(</span>times, stringConcatenationTest<span class="parenthesis">)</span>;
<span class="line_number">53</span>
<span class="line_number">54</span>            System.out.println<span class="parenthesis">(</span><span class="string_constant">&quot;Results for iteration &quot;</span> + loopCount<span class="parenthesis">)</span>;
<span class="line_number">55</span>            System.out.println<span class="parenthesis">(</span><span class="string_constant">&quot;StringBuffer Build. &quot;</span> + stringBuffElapsed<span class="parenthesis">)</span>;
<span class="line_number">56</span>            System.out.println<span class="parenthesis">(</span><span class="string_constant">&quot;String  Concatenat. &quot;</span> + stringConcatElapsed + <span class="string_constant">&quot;\n&quot;</span><span class="parenthesis">)</span>;
<span class="line_number">57</span>        <span class="parenthesis">}</span>
<span class="line_number">58</span>    <span class="parenthesis">}</span>
<span class="line_number">59</span><span class="parenthesis">}</span></span>
</pre>
<p>Here the output:</p>
<pre>
Results for iteration 1
StringBuffer Build. 3085
String  Concatenat. 1492

Results for iteration 2
StringBuffer Build. 3044
String  Concatenat. 1612

Results for iteration 3
StringBuffer Build. 3205
String  Concatenat. 1793

Results for iteration 4
StringBuffer Build. 3745
String  Concatenat. 1783

Results for iteration 5
StringBuffer Build. 3505
String  Concatenat. 2353
</pre>
<p>For this case, String concatenations is twice faster than StringBuffer!</p>
<p>Conclusions: don&#8217;t use String concatenations to build big strings (expecially inside loops), use StringBuffers everytime possible, but leave your source code readable! And&#8230; never forget <a href="http://c2.com/cgi/wiki?RulesOfOptimization">Rules of Optimization</a>. Personally, I prefere code (a little) slower but more readable. And, when possible, faster and more readable, like in this case.
<div id="crp_related">
<h4>Related Posts:</h4>
<ul>
<li><a href="http://en.newinstance.it/2008/11/04/dynamic-tests-with-junit-3/" rel="bookmark" class="crp_title">Dynamic tests with JUnit 3</a></li>
<li><a href="http://en.newinstance.it/2008/10/24/always-on-getter-and-setters/" rel="bookmark" class="crp_title">Always on getter and setters</a></li>
<li><a href="http://en.newinstance.it/2008/10/24/the-repetita-juvant-principle/" rel="bookmark" class="crp_title">The Repetita Juvant Principle</a></li>
<li><a href="http://en.newinstance.it/2006/11/19/reading-javadocs-from-inside-the-original-zip-file/" rel="bookmark" class="crp_title">Reading Javadocs from inside the original zip file</a></li>
<li><a href="http://en.newinstance.it/2008/11/22/random-thoughts-about-unchecked-exceptions/" rel="bookmark" class="crp_title">Random thoughts about unchecked exceptions</a></li>
</ul>
</div>
<div class="shr-publisher-216"></div>
<p><!-- Start Shareaholic LikeButtonSetBottom Automatic -->
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2005%2F06%2F07%2Fstringbuffer-considered-harmuful%2F' data-shr_title='StringBuffer+considered+harmuful'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2005%2F06%2F07%2Fstringbuffer-considered-harmuful%2F' data-shr_title='StringBuffer+considered+harmuful'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2005%2F06%2F07%2Fstringbuffer-considered-harmuful%2F' data-shr_title='StringBuffer+considered+harmuful'></a></div>
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<p><!-- End Shareaholic LikeButtonSetBottom Automatic --></p>
]]></content:encoded>
			<wfw:commentRss>http://en.newinstance.it/2005/06/07/stringbuffer-considered-harmuful/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

