<?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>Manuel Aldana</title>
	<atom:link href="http://www.aldana-online.de/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.aldana-online.de</link>
	<description>Software Engineering: blog &#38; .lessons_learned</description>
	<lastBuildDate>Sun, 27 Jun 2010 21:49:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>From Java Easymock to Mockito</title>
		<link>http://www.aldana-online.de/2010/06/27/from-java-easymock-to-mockito/</link>
		<comments>http://www.aldana-online.de/2010/06/27/from-java-easymock-to-mockito/#comments</comments>
		<pubDate>Sun, 27 Jun 2010 13:29:10 +0000</pubDate>
		<dc:creator>manuel aldana</dc:creator>
				<category><![CDATA[Continous Integration]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Technologies/Tools]]></category>

		<guid isPermaLink="false">http://www.aldana-online.de/?p=174</guid>
		<description><![CDATA[While browsing through open-source project sonar&#8217;s test-code I noticed that they had package imports with Mockito namespace. What I noticed was that the mocking test-code looked similar to easymock but less cluttered and better readable. So I gave Mockito (version was 1.8.3 back then) a try when implementing new test-cases and did not regret it [...]]]></description>
			<content:encoded><![CDATA[<p>While browsing through open-source project sonar&#8217;s test-code I noticed that they had package imports with <a href="http://mockito.org/" target="_blank">Mockito</a> namespace. What I noticed was that the mocking test-code looked similar to <a href="http://www.easymock.org/" target="_blank">easymock</a> but less cluttered and better readable. So I gave Mockito (version was 1.8.3 back then) a try when implementing new test-cases and did not regret it :).</p>
<h3>Easymock before</h3>
<p>Around 2005 there were several mocking frameworks available. The main reason I chose to work with easymock was that it was both powerful and refactoring friendly. It supports automatic safe refactorings well because the expectations on method calls aren&#8217;t setup as a loose string-snippet but on statically typed info (method call expectations are directly bound to the object-type).</p>
<p>Though I found easymock great and made stubbing and mocking much easier as before, I found it had some drawbacks (speaking of version 2.5):</p>
<ul>
<li>The mocking/stubbing of interfaces vs. classes is not transparent. It is done through different Main-classes (EasyMock + classextension.EasyMock). This implied that mixing mocking both interfaces and classes inside one test-class followed in cluttered code and importing hell.</li>
<li>The error messages of easymock are confusing sometimes. Often it is not clear whether the test-case has failed or easymock was used wrong (e.g. forgetting to call replay()).</li>
<li>The mandatory call of replay() after having setup the mocked object always felt redundant and made test-case longer.</li>
<li>The non-clear separation between setting up a mock and verifying it. Setting up a mock added also a verification on all expectations as soon as you called verify(). When writing + reading test-code this always confused me, because you already had to cope with verify logic in the setup part of the test-case.</li>
</ul>
<h3>Mockito after</h3>
<p>The guys of <a href="http://mockito.org/" target="_blank">Mockito</a> say that they were inspired by Easymock and indeed you see its heritage. After having used it for about 3 months now so far the hands-on impressions are great and I now exclusively use Mockito for writing unit-tests.</p>
<p>My positive experiences were:</p>
<ul>
<li>Test-code still is safe in regard of using static-typed based automatic refactorings.</li>
<li>Transparency of classes vs. interfaces. In both cases you call Mockito.mock(MyInterface.class) or Mockito.mock(MyClass.class).</li>
<li>Clear seperation between setting up a mock and verifiying it. This feels more intuitive and the clear setup/excercise/verify test-code order is preserved.</li>
<li>Helpful error message, when an assertion wasn&#8217;t met or the tool guessed a framework usage error.</li>
<li>The naming of methods is intuitive (like when(), thenReturn()).</li>
<li>When earlier I used the real domain-objects as test-data (i.e. by filling data through setters/constructors), now I use mockito to stub them (i.e. stubbing the getters). Domain code logic has now much less impact on test-runs.</li>
<li>Nice short, straightforward <a href="http://mockito.googlecode.com/svn/tags/latest/javadoc/org/mockito/Mockito.html" target="_blank">documentation</a>.</li>
<li>A great name + logo ;)</li>
</ul>
<p>In summary: The mockito folks did a great job (they took the nice ideas from Easymock creator and improved its drawbacks). Now looking at old test-code using Easymock I subjectively need much more time to grasp what the intent of the test is. With Mockito the test-cases read more like a clear sequential &#8220;requirements story&#8221; like test-cases always should.</p>
<h3>Migration of test-code</h3>
<p>If you are already using easymock the tool switch is amazingly quick. Following migration path helped me:</p>
<ol>
<li>Give yourself and your colleagues around two weeks investing time to work with the tool and get comfortable with it. Write all your new test-classes with Mockito.</li>
<li>If you like it make the switch: Explicitly communicate that using the old mocking framework is deprecated (if possible use static code analysis tools where you can mark severaly packages deprecated (org.easymock.*)). Now usage of Mockito for new test-classes should be mandatory.</li>
<li>If you have already big test-codebase I do NOT recommend a big-bang test-code migration. Such migration work is time consuming and boring. Therefore taking the incremental approach is better: Only migrate Easymock code to Mockito in case you anyway touch the class, i.e. are modifying or adding test-cases.</li>
</ol>
<p>Looking at the test-migrations I did so far, migrating Easymock code to Mockito is quite straightforward. Get rid of all replay(), verify() calls and adjust to the slight API changes. The only thing you have to watch out for more are the explicit verification on mocked-calls. Easymock did implicitly verify all expectations when calling verify() on the mock-object, on Mockito side you explicitly have to call verifications on each method. The same counts for strict mocks. You have to add respective verifications.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aldana-online.de/2010/06/27/from-java-easymock-to-mockito/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inside-Out Modularization</title>
		<link>http://www.aldana-online.de/2010/05/30/inside-out-modularization/</link>
		<comments>http://www.aldana-online.de/2010/05/30/inside-out-modularization/#comments</comments>
		<pubDate>Sun, 30 May 2010 13:57:52 +0000</pubDate>
		<dc:creator>manuel aldana</dc:creator>
				<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Software Maintenance]]></category>

		<guid isPermaLink="false">http://www.aldana-online.de/?p=166</guid>
		<description><![CDATA[A appropriate modularization of your codebase is important. It has positive side-effects in many directions (testability, code comprehensability, build-speed etc.). Still there are different levels of modularization. These levels can be categorized from fine-grained to coarse grained.
Note: For simplicty throughout the post I will use java terms (class, method, package). Of course this can be [...]]]></description>
			<content:encoded><![CDATA[<p>A appropriate modularization of your codebase is important. It has positive side-effects in many directions (testability, code comprehensability, build-speed etc.). Still there are different levels of modularization. These levels can be categorized from fine-grained to coarse grained.</p>
<p><em>Note: For simplicty throughout the post I will use java terms (class, method, package). Of course this can be mapped to other languages constructs like functions, file-includes or plain-script statements.</em></p>
<p style="text-align: center">
<img class="size-full wp-image-167  aligncenter" title="inside-out" src="http://www.aldana-online.de/wp-content/uploads/2010/05/inside-out.png" alt="" width="350" height="151" /></p>
<p>Advantage of more fine grained modularization:</p>
<ul>
<li>Maintaining less artifacts (e.g. files, packages, libraries) makes the build/deployment-lifecyle easier.</li>
<li>For simple features code browsing gets easier (&#8220;You see all stuff with one eye-sight&#8221;)</li>
</ul>
<p>The drawback is that the fine grained approach doesn&#8217;t scale: The bigger the codebase gets the more difficult it is to &#8220;see&#8221; any modularization or separatation of concerns. The coarse grained modularization gives you advantage here:</p>
<ul>
<li>Bigger systems are easier to comprehend if the &#8220;split&#8221; is done on package or library level.</li>
<li>Refactorings are getting easier because inside the modules the direct numbers of dependencies get less (submodules only import dependencies they need).</li>
<li>Unit-test setup gets easier (for reason see Refactoring)</li>
</ul>
<h3>Where to start?</h3>
<p>The question is at which modularization level you should start. There are two major antipatterns, either developers sticked on too fine level (e.g. 6000 LOC inside one single file) or they started on a too coarse level (e.g. each of the many packages only contains one or two classes). The too coarse pattern often occurs if you overengineer solution.</p>
<h4>Code from scratch</h4>
<p>To avoid the too fine/coarse pitfall I follow the Inside-Out modularization approach:</p>
<ol>
<li>Start to edit a single file. Implement the highest priority requirements of feature inside the most fine grained &#8220;module&#8221; your language can you offer (e.g. class-method).</li>
<li> When code inside a method gets bigger and you lose overview try to cluster statements (e.g. by speparating them with line-breaks).</li>
<li>When code statement clusters get too many and you see duplications, extract these section to a new method.</li>
<li>When there are too many methods and the lines of code inside the single file are very high, cluster your methods by problem domain and extract them to a new class in the same package.</li>
<li>When there are too many classes inside on package, either create a subpackage or sibling-package which fit to the problem domain (separation of concerns).</li>
<li>When a package hierachy/tree gets too deep and wide, create a new package hierachy (e.g. com.foo becomes com.foo.system1 and com.foo.system2)</li>
<li>When there are too many package hierachies inside one library (like .jar), create another library-project (e.g. Maven project/module).</li>
</ol>
<h4>Integrate changes in existing code</h4>
<p>Above is a more or less complete list when starting with code from scratch. But how does it apply to existing code and integrating changes? The main principle is the same but you would start your Inside-Out modularization on a different level. As Example: If you have to add code inside a class and see it you feature-adding would result in too many methods you start off with step number four (extracting class).</p>
<h3>At which step to level up?</h3>
<p>It is always the question, when to level up from a fine to a more coarse grained modularization. It is very difficult to have a thumb of a rule, because this highly matters on code-style taste, on density of <em>&#8216;if/else&#8217;</em> logic and also on the problem-domain you are trying to solve. A very good test is either ask colleagues for review whether the modularization is intuitive or take another look the next day or a week after to get a fresh view.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aldana-online.de/2010/05/30/inside-out-modularization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Codebase size implications on Software development</title>
		<link>http://www.aldana-online.de/2010/05/09/process-implications-of-metric-lines-of-code-loc/</link>
		<comments>http://www.aldana-online.de/2010/05/09/process-implications-of-metric-lines-of-code-loc/#comments</comments>
		<pubDate>Sun, 09 May 2010 19:17:59 +0000</pubDate>
		<dc:creator>manuel aldana</dc:creator>
				<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Software Maintenance]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.aldana-online.de/?p=158</guid>
		<description><![CDATA[Following discusses the implications of big codebases. Codebase size can be measured with the well known &#8216;lines of code&#8217; (LOC) metric. 
The following codebase size and LOC metric scope is not fine grained on function or class level but for complete codebase or at least on subcomponent level.
Bad (anti-pattern): Codebase size as progress metric
Sometimes (though [...]]]></description>
			<content:encoded><![CDATA[<p>Following discusses the implications of big codebases. Codebase size can be measured with the well known &#8216;lines of code&#8217; (LOC) metric. </p>
<p>The following codebase size and LOC metric scope is not fine grained on function or class level but for complete codebase or at least on subcomponent level.</p>
<h3>Bad (anti-pattern): Codebase size as progress metric</h3>
<p>Sometimes (though fortunately rarely) QA or project management is taking codebase size and LOC as a progress metric to see what the project&#8217;s state is. The more lines of code have been written the closer the project is seen to have been completed. This is a definite anti-pattern for following reasons:</p>
<ul>
<li>It is extremely difficult to estimate, how much code will be necessary for a certain scope or a set of requirements. This implies that project or product management cannot know, how much code is missing to mark the requirements as done.</li>
<li>It is more about quality as of quantity of code. Well structured code with avoidance of duplication tends to have less lines of code.</li>
<li>It is very important and valuable to throw away dead code (code which isn&#8217;t used or executed anywhere). Using lines of code as a progress metric would mean this important refactoring will cause a negative project progress.</li>
</ul>
<h3>Good: Codebase size as compexity metric</h3>
<p>With a higher LOC metric you are likely to face following problems:</p>
<ul>
<li>Increase of feeback time: It takes longer to build deployable artifacts, to startup application and to verify implementation behaviour (this both applies to local development and CI servers).</li>
<li>Tougher requirements on development tools: Working on large codebases makes the IDE often run less smoothly (e.g. while doing refactorings, using several debugging techniques).</li>
<li>Code comprehension: More time has to be spent for reverse engineering or reading/understanding documentation. Code comprehension is vital to integrate changes and debugging.</li>
<li>More complex test-setup: Bigger codebases tend to have more complicated test-setup. This includes setting up external components (like databases, containers, message-queues) and also defining test-data (the domain model is likely to be rich).</li>
<li>Fixing bugs: First of all exposing a bug is harder (see test-setup). Further more localization of bug is tougher, because more code has to be narrowed down. Potentially more theories exist to have causes the bug.</li>
<li>Breaking code: New requirements are more difficult to implement and integrate without breaking existing functionality.</li>
<li>Product knowledge leakage: Bigger codebases tend to cover more functionality. The danger increases, that at some point the organization loses knowledge which functionality the software supports. This blindness has very bad implications on defining further requirements or strategies.
<li>Compatibility efforts: The larger a codebase the more likely it is that it already has a long lifetime (codebases tend to grow over the years). Along the age of software down-compatibility is a constant requirement, which increases (a lot of) effort.</li>
<li>Team size + fluctuation: Bigger codebases tend to have been touched by a big size of developers, which can cause knowledge leakage. Due to communication complexity, each developer only knows just a little part of the system and does not distribute it. Even worse due to team-size fluctuation is likely to be higher and knowledge gets completely lost for company.</li>
<li>etc. &#8230;</li>
</ul>
<h3>Quantification of LOC impact is hard</h3>
<p>Above statements are more qualitative and are not quantifiyable, because the exact mapping of a certain LOC number to a magic complexity number is unfeasible. For instance there are other criterias which have an impact on the complexity of a software system, which are independent of LOC:</p>
<ul>
<li>Choice of programming language/system: Maintaining 1.000 LOC of assembly is a complete different story as doing it with 1.000 of Java code.</li>
<li>Problem domain: Complex algorithms (e.g. to be found in AI or image processing) tend to have less lines of code but still are complicated.</li>
<li>Heterogenity of chosen technology in your complete source-code ecosystem: E.g. using 10 different frameworks and/or programming-languages and making them integrate to the overall system harder as concentrating on one  framework.</li>
<li>Quality and existence of documentation: E.g. Api-interfaces aren&#8217;t documented or motivations for major design decision are unknown. From developers point of view such a system is effectively more complex because a lot of effort has to be spent in reverse engineering.</li>
<li>etc. &#8230;</li>
</ul>
<h3>Conclusion</h3>
<p>The metric LOC representing codebase size has a big impact on your whole software development cycle. Therefore it should be measured, observed and tracked over time (also by subcomponent). Apart from showing you the current state and evolution of your codebase from historical point of view you can also use it proactively for future:</p>
<ul>
<li>Estimation/planning: When estimating features take the LOC metric has influence criteria. The higher the LOC the more complicated it will be to integrate feature.</li>
<li>YAGNI: Take YAGNI (&#8220;you ain&#8217;t gonna need it&#8221;) principle to the extreme. Only implement really necessary features. Do not make your software over-extensible and as simple as possible.</li>
<li>Refactor out dead code: Being aware of LOC as a complexity metric, you can create a culture of dead-code awareness. Throw away as much unused code away as you can.</li>
<li>Refactor out dead functionality: Software products often are unneccessarily overcomplex. Also push business towards are more simple product strategy and throw away unused features and achieve a smaller codebase.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.aldana-online.de/2010/05/09/process-implications-of-metric-lines-of-code-loc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tomcat JDBC-Realm in digest mode</title>
		<link>http://www.aldana-online.de/2010/04/05/tomcat-jdbc-realm-in-digest-mode/</link>
		<comments>http://www.aldana-online.de/2010/04/05/tomcat-jdbc-realm-in-digest-mode/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 11:57:38 +0000</pubDate>
		<dc:creator>manuel aldana</dc:creator>
				<category><![CDATA[Technologies/Tools]]></category>

		<guid isPermaLink="false">http://www.aldana-online.de/?p=154</guid>
		<description><![CDATA[tomcat, realm digest style, jdbc]]></description>
			<content:encoded><![CDATA[<p>Though the <a href="http://tomcat.apache.org/tomcat-6.0-doc/realm-howto.html" target="_blank">tomcat-docs</a> gives most information, there are some pitfalls when using tomcats facilities for HTTP Auth in Digest mode including hashed passwords. Following is a list to avoid them (tested on tomcat 6.0.x).</p>
<h3>JDBC Driver to classpath</h3>
<p>Tomcat realm handling is container internal, therefore it is not enough to have jdbc-driver (e.g. mysql-connector-java-5.1.6.jar) in your application classpath. You have to explicit add it to the container classpath (e.g. TOMCAT_HOME/lib).</p>
<h3>Configuration Snippets</h3>
<p>Tomcat container config, which can appear as nested element inside &lt;Engine&gt;, &lt;Host&gt; or &lt;Context&gt; (e.g. TOMCAT_HOME/conf/context.xml):</p>
<pre>
<div class="codesnip-container" >
<div class="codesnip">...
<span class="sc3"><span class="coMULTI">&lt;!-- database connection settings + enabling hashed passwords (MD5 sum style) --&gt;</span></span>
<span class="sc3"><span class="re1">&lt;Realm</span>
&nbsp;<span class="re0">className</span>=<span class="st0">"org.apache.catalina.realm.JDBCRealm"</span>
&nbsp;<span class="re0">digest</span>=<span class="st0">"MD5"</span>
&nbsp;<span class="re0">driverName</span>=<span class="st0">"com.mysql.jdbc.Driver"</span>
&nbsp;<span class="re0">connectionURL</span>=<span class="st0">"jdbcURL"</span>
&nbsp;<span class="re0">connectionName</span>=<span class="st0">"dbUser"</span>
&nbsp;<span class="re0">connectionPassword</span>=<span class="st0">"dbPwd"</span>
&nbsp;<span class="re0">userRoleTable</span>=<span class="st0">"role_table"</span>
&nbsp;<span class="re0">userTable</span>=<span class="st0">"user_table"</span>
&nbsp;<span class="re0">userNameCol</span>=<span class="st0">"dbuser_column"</span>
&nbsp;<span class="re0">userCredCol</span>=<span class="st0">"dbpwd_column"</span>
&nbsp;<span class="re0">roleNameCol</span>=<span class="st0">"role_column"</span><span class="re2">/&gt;</span></span>
...</div>
</div>
</pre>
<p>Webapplication web.xml:</p>
<pre>
<div class="codesnip-container" >
<div class="codesnip"><span class="sc3"><span class="re1">&lt;web</span>-app<span class="re2">&gt;</span></span>
...
&nbsp;<span class="sc3"><span class="re1">&lt;security</span>-constraint<span class="re2">&gt;</span></span>
&nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;web</span>-resource-collection<span class="re2">&gt;</span></span>
&nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;web</span>-resource-name<span class="re2">&gt;</span></span>Secure area<span class="sc3"><span class="re1">&lt;/web</span>-resource-name<span class="re2">&gt;</span></span>
&nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;url</span>-pattern<span class="re2">&gt;</span></span>/*<span class="sc3"><span class="re1">&lt;/url</span>-pattern<span class="re2">&gt;</span></span>
&nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;/web</span>-resource-collection<span class="re2">&gt;</span></span>
&nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;auth</span>-constraint<span class="re2">&gt;</span></span>
&nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;role</span>-name<span class="re2">&gt;</span></span>admin<span class="sc3"><span class="re1">&lt;/role</span>-name<span class="re2">&gt;</span></span>
&nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;/auth</span>-constraint<span class="re2">&gt;</span></span>
&nbsp;<span class="sc3"><span class="re1">&lt;/security</span>-constraint<span class="re2">&gt;</span></span>

&nbsp;<span class="sc3"><span class="re1">&lt;login</span>-config<span class="re2">&gt;</span></span>
&nbsp; &nbsp;<span class="sc3"><span class="coMULTI">&lt;!-- enabling HTTP Auth digest mode --&gt;</span></span>
&nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;auth</span>-method<span class="re2">&gt;</span></span>DIGEST<span class="sc3"><span class="re1">&lt;/auth</span>-method<span class="re2">&gt;</span></span>
&nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;realm</span>-name<span class="re2">&gt;</span></span>your-realm<span class="sc3"><span class="re1">&lt;/realm</span>-name<span class="re2">&gt;</span></span>
&nbsp;<span class="sc3"><span class="re1">&lt;/login</span>-config<span class="re2">&gt;</span></span>

&nbsp;<span class="sc3"><span class="coMULTI">&lt;!-- roles must be defined to be used in security-constraint --&gt;</span></span>
&nbsp;<span class="sc3"><span class="re1">&lt;security</span>-role<span class="re2">&gt;</span></span>
&nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;description<span class="re2">&gt;</span></span></span>Role sample<span class="sc3"><span class="re1">&lt;/description<span class="re2">&gt;</span></span></span>
&nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;role</span>-name<span class="re2">&gt;</span></span>admin<span class="sc3"><span class="re1">&lt;/role</span>-name<span class="re2">&gt;</span></span>
&nbsp;<span class="sc3"><span class="re1">&lt;/security</span>-role<span class="re2">&gt;</span></span>
...
<span class="sc3"><span class="re1">&lt;/web</span>-app<span class="re2">&gt;</span></span></div>
</div>
</pre>
<h3>Password patterns</h3>
<p>For HTTP Auth Digest tomcat expects a special cleartext pattern for the hashed password entry inside the database. Unfortunately the cleartext snippet is different from the one from Http Auth Basic (this took me some time to find out&#8230;).</p>
<p>Bash CLI samples for HTTP Auth password hashing (md5sum):</p>
<pre>
<div class="codesnip-container" ># Basic style (only the password without user or realm info is hashed)
echo -n password | md5sum
# Digest style (<b>'your-realm'</b> is entry from web.xml-&gt;login-config-&gt;realm-name)
echo -n username:your-realm:password | md5sum</div>
</pre>
<h3>Migration HTTP Auth Basic to Digest</h3>
<p>As you saw above tomcats Auth Basic and Digest cleartext password patterns are different. Therefore just switching the entry of <b>web.xml-&gt;login-config-&gt;auth-method</b> from <b>&#8216;BASIC&#8217;</b> to <b>&#8216;DIGEST&#8217;</b> wouldn&#8217;t suffice. I recommend to completely create a new database column (e.g. passwords_digest) so the separation and transition-path between Basic and Digest style is more clear. In case you hashed the Basic passwords already further more you have to reset the user passwords (the nature of good hashes are that you practically cannot map back to cleartext).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aldana-online.de/2010/04/05/tomcat-jdbc-realm-in-digest-mode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extending source-code syntax highlighting</title>
		<link>http://www.aldana-online.de/2009/12/13/extending-source-code-syntax-highlighting/</link>
		<comments>http://www.aldana-online.de/2009/12/13/extending-source-code-syntax-highlighting/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 12:39:13 +0000</pubDate>
		<dc:creator>manuel aldana</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.aldana-online.de/?p=133</guid>
		<description><![CDATA[After all the decades of software development, and recently hyped trends (e.g. &#8220;programming in graphical diagrams&#8221;) plain text source code is still the most powerful way to build software systems. Regarding this a high degree of importance is readability and comprehension of source code. In fact you&#8217;re spending more time in reading as with writing [...]]]></description>
			<content:encoded><![CDATA[<p>After all the decades of software development, and recently hyped trends (e.g. &#8220;programming in graphical diagrams&#8221;) plain text source code is still the most powerful way to build software systems. Regarding this a high degree of importance is readability and comprehension of source code. In fact you&#8217;re spending more time in reading as with writing code. Apart from improving the structure of the code itself (the refactoring concept plays a big role here) syntax highlighting is also very important to get a quick overview. Following gives an example how and  why to tweak your editor defaults.</p>
<h3>IDE defaults</h3>
<p>Defaults from several IDEs or more simple text-editors are already giving big help, e.g. in showing keywords, instance fields or comments. Still in my view they can be tweaked, most of editors give options to extend things. Either they work with a graphical interface for changing settings (IDEs like IntelliJ, Eclipse etc.) or are working themselves with plain text highlighting configuration files (vim, krusader etc.). Your syntax highlighting toolbox contains text-decorations (like italic, underscored, bold) and coloring (foreground, background).<br />
For my tweaks I used my favorite IDE IntelliJ, which offers many syntax highlighting options. Just checkout your editor and see what is possible.</p>
<h3>Example BEFORE</h3>
<p>Following annoyed me on the default settings:</p>
<ul>
<li>Could not instantly see parameters and variables</li>
<li>No difference between local-vars and parameters</li>
<li>Non-javadoc comments were too grey. I write comments to explain the &#8216;Why&#8217; or a important block of a code statement. So comments should be better visible.</li>
<li>Todo comments were blue. Blue is a too &#8220;friendly&#8221; color to me, whereas looking at todos should wake me up!</li>
<li>Instance and static vars were colored the same though they have different semantics.</li>
<li>I tend to use more smaller methods as one monster method. The default highlighting does not separate between method declarations and calls.</li>
</ul>
<p>The BEFORE snippet:<br />
<img class="aligncenter" src="http://www.aldana-online.de/wp-content/uploads/2009/12/before.png" alt="before" /></p>
<h3>Example AFTER</h3>
<p>I changed settings to:</p>
<ul>
<li>Non-instance + static variables are blue now. Parameters should be handled with more care. (changing them side-effect the callee), so they are bold.</li>
<li>Static and instance vars have different colors now (pink vs. violet).</li>
<li>Comments have slight green background now.</li>
<li>Todo flags have the signal-color orange</li>
<li>Methods are underscored. Declarations are bold, calls are non-bold.</li>
</ul>
<p>The AFTER snippet:<br />
<img class="aligncenter" src="http://www.aldana-online.de/wp-content/uploads/2009/12/after.png" alt="after" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.aldana-online.de/2009/12/13/extending-source-code-syntax-highlighting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Most favorite firefox addons/plugins</title>
		<link>http://www.aldana-online.de/2009/11/21/most-favorite-firefox-addons/</link>
		<comments>http://www.aldana-online.de/2009/11/21/most-favorite-firefox-addons/#comments</comments>
		<pubDate>Sat, 21 Nov 2009 12:03:13 +0000</pubDate>
		<dc:creator>manuel aldana</dc:creator>
				<category><![CDATA[Technologies/Tools]]></category>

		<guid isPermaLink="false">http://www.aldana-online.de/?p=132</guid>
		<description><![CDATA[One of firefox killer-features is the variety of add-ons. Following is an overview of the add-ons I use currently.
Vimperator
Vimperator is a real gem! Adds some vim (editor) feeling to the browser. Makes you faster, because nearly all mouse action can be supplemented with keyboard shortcuts. Also automates more complicated flows with macros. At start using [...]]]></description>
			<content:encoded><![CDATA[<p>One of firefox killer-features is the variety of add-ons. Following is an overview of the add-ons I use currently.</p>
<h3>Vimperator</h3>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/4891https://addons.mozilla.org/en-US/firefox/addon/4891" target="_blank">Vimperator</a> is a real gem! Adds some vim (editor) feeling to the browser. Makes you faster, because nearly all mouse action can be supplemented with keyboard shortcuts. Also automates more complicated flows with macros. At start using vimperator can be somewhat annoying because pressing some keys do unexpected things, but investing time to get used to it pays off definetely.</p>
<h3>Xmarks</h3>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/2410" target="_blank">Xmarks</a> saves your bookmarks to a server and makes synchronization possible between different machines. Very handy if you are working from different computers. Most likely it could be replaced by upcoming firefox 4 which offers this functionality in its core.</p>
<h3>Web Developer</h3>
<p><a href="http://addons.mozilla.org/en-US/firefox/addon/60" target="_blank">Web Developer</a> is a nice webdeveloper testing kit. Numerous things can be done like style/CSS testing, gathering meta-information of the page, handling cookies, finding broken images.</p>
<h3>Firebug</h3>
<p><a href="http://addons.mozilla.org/en-US/firefox/addon/1843" target="_blank">Firebug</a> is a perfect accompany to Webdeveloper for testing/analyzing websites. Offers JavaScript debugging, analyzing DOM tree, viewing CSS styleor watching HTTP calls and request/response contents. It is also plugin aware (see below).</p>
<h3>Firecookie</h3>
<p><a href="http://addons.mozilla.org/en-US/firefox/addon/6683" target="_blank">Firecookie</a> is an addon for firebug. Makes cookies handling (reading, deleting, editing) much easier as with Webdeveloper plugin.</p>
<h3>YSlow</h3>
<p><a href="http://addons.mozilla.org/en-US/firefox/addon/5369" target="_blank">YSlow</a> is an addon for firebug, which offers performance test for webapplications. Gives a good overview how your site performs and gives a summary in grade style (A-F). If it gives you bad grade, still question whether they are appropriate in your special case (e.g. YSlow moans about missing CDNs, but an usage of a CDN doesn&#8217;t always makes sense or you don&#8217;t have any control over certain included components).</p>
<h3>Live HTTP Headers</h3>
<p>Firebug offers good HTTP traffic tracking. But sometimes I also use <a href="http://addons.mozilla.org/en-US/firefox/addon/3829" target="_blank">Live HTTP Headers</a> because you can filter tracking HTTP calls by URL and content-type, for HTTP POST you can set your own defined payload.</p>
<h3>JSONView</h3>
<p>When testing webapps, instead of using curl sometimes it is handy to fire a HTTP request directly through firefox. If doing so by default firefox makes problems and prompts to save json (Content-type: application/json) as a file to instead of just displaying the content inside the browser window. <a href="http://addons.mozilla.org/en-US/firefox/addon/10869" target="_blank">JSONView</a> bypasses this and displays json content appropriately.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aldana-online.de/2009/11/21/most-favorite-firefox-addons/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parameterized test-methods with TestNG</title>
		<link>http://www.aldana-online.de/2009/04/19/parameterized-test-methods-with-testng/</link>
		<comments>http://www.aldana-online.de/2009/04/19/parameterized-test-methods-with-testng/#comments</comments>
		<pubDate>Sun, 19 Apr 2009 10:08:10 +0000</pubDate>
		<dc:creator>manuel aldana</dc:creator>
				<category><![CDATA[Continous Integration]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[parameterized test case]]></category>
		<category><![CDATA[test-ng]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://www.aldana-online.de/?p=131</guid>
		<description><![CDATA[ TestNG offers many great features and is definitely more capable as JUnit to build a strong automated Test-Suite. When writing test-cases one important factor is the handling of test-data. With JUnit it is cumbersome to feed different test-data to the same test-code. TestNG solves this much better.
Let&#8217;s look at a very simple example. When [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://testng.org/doc/index.html" target="_blank"> TestNG</a> offers many great features and is definitely more capable as JUnit to build a strong automated Test-Suite. When writing test-cases one important factor is the handling of test-data. With JUnit it is cumbersome to feed different test-data to the same test-code. TestNG solves this much better.</p>
<p>Let&#8217;s look at a very simple example. When trying to test an exception with JUnit 4 with different test-data I would need to write something like:</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw2">class</span> MyTest<span class="br0">&#123;</span></p>
<p>&nbsp; @Test<br />
&nbsp; <span class="kw2">public</span> <span class="kw4">void</span> throw_exception_if_wrong_input<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw2">try</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw2">new</span> Foo<span class="br0">&#40;</span><span class="st0">&#8220;test-data1&#8243;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; fail<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><span class="kw2">catch</span><span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AIllegalArgumentException+java.sun.com&#038;bntl=1"><span class="kw3">IllegalArgumentException</span></a> iae<span class="br0">&#41;</span><span class="br0">&#123;</span><span class="br0">&#125;</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp; <span class="kw2">try</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw2">new</span> Foo<span class="br0">&#40;</span><span class="st0">&#8220;test-data2&#8243;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; fail<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><span class="kw2">catch</span><span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AIllegalArgumentException+java.sun.com&#038;bntl=1"><span class="kw3">IllegalArgumentException</span></a> iae<span class="br0">&#41;</span><span class="br0">&#123;</span><span class="br0">&#125;</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp; <span class="kw2">try</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw2">new</span> Foo<span class="br0">&#40;</span><span class="st0">&#8220;test-data3&#8243;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; fail<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><span class="kw2">catch</span><span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AIllegalArgumentException+java.sun.com&#038;bntl=1"><span class="kw3">IllegalArgumentException</span></a> iae<span class="br0">&#41;</span><span class="br0">&#123;</span><span class="br0">&#125;</span>&nbsp; &nbsp; <br />
&nbsp; <span class="br0">&#125;</span></p>
<p><span class="br0">&#125;</span></div>
</div>
<p>This code has essential problems:</p>
<ol>
<li> Because I want to avoid to write two more test-methods (essentialy the same production code is triggered), I am putting three test-cases into one test-method, which is bad practice. This is because test cases aren&#8217;t using the tearDown and setUp facilities and cannot guarantee isolation. That is also the reason that I could not use the excpectedException parameter inside the JUnit 4 @Test annotation. Alternative is to really use three test-methods, but code readability then suffers.
</li>
<li> Even though above example is very simplified (only <em>new Foo()</em> is called) the test-code is not expressive. Surely you could improve this by extracting method and giving a good name. But still it is a bit blurry, why we do so and that it is just for using different test-data.
</li>
</ol>
<h3>TestNG parameterized test-methods</h3>
<p>TestNG does it better and builds the &#8220;test-case differs only in test-data&#8221; situation into its framework. This is done by building a DataProvider and passing parameters to the test-method. This way code gets more expressive and each different test-data set is executed as an isolated test-case also. Here an example of the TestNG version of above test-cases (I followed the code centric way, you can also configure your DataProvider through an XML file):</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw2">class</span> MyTest<span class="br0">&#123;</span></p>
<p>&nbsp; @DataProvider<span class="br0">&#40;</span>name = <span class="st0">&#8220;wrong_input&#8221;</span><span class="br0">&#41;</span><br />
&nbsp; <span class="kw2">public</span> <a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&#038;bntl=1"><span class="kw3">Object</span></a><span class="br0">&#91;</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="br0">&#93;</span> createData<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="co1">//2 dimensions</span><br />
&nbsp; &nbsp; <span class="co1">// x: data-set for one test-case</span><br />
&nbsp; &nbsp; <span class="co1">// y: set of parameters (test-method can contain multiple parameters)</span><br />
&nbsp; &nbsp; <span class="kw2">return</span> <span class="kw2">new</span> <a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&#038;bntl=1"><span class="kw3">Object</span></a><span class="br0">&#91;</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="br0">&#93;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><span class="st0">&#8220;test-data-1&#8243;</span><span class="br0">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><span class="st0">&#8220;test-data-2&#8243;</span><span class="br0">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><span class="st0">&#8220;test-data-3&#8243;</span><span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span>;<br />
&nbsp;<span class="br0">&#125;</span></p>
<p>&nbsp;@Test<span class="br0">&#40;</span>expectedExceptions = <a href="http://www.google.com/search?q=allinurl%3AIllegalArgumentException+java.sun.com&#038;bntl=1"><span class="kw3">IllegalArgumentException</span></a>.<span class="kw2">class</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dataProvider = <span class="st0">&#8220;wrong_input&#8221;</span><span class="br0">&#41;</span><br />
&nbsp;<span class="kw2">public</span> <span class="kw4">void</span> throw_exception_if_bad_input<span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&#038;bntl=1"><span class="kw3">String</span></a> input<span class="br0">&#41;</span><br />
&nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp;<span class="kw2">new</span> Foo<span class="br0">&#40;</span>input<span class="br0">&#41;</span><br />
&nbsp;<span class="br0">&#125;</span><br />
&nbsp;<br />
<span class="br0">&#125;</span></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.aldana-online.de/2009/04/19/parameterized-test-methods-with-testng/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reasons NOT to use ClearCase</title>
		<link>http://www.aldana-online.de/2009/03/19/reasons-why-you-should-stay-away-from-clearcase/</link>
		<comments>http://www.aldana-online.de/2009/03/19/reasons-why-you-should-stay-away-from-clearcase/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 00:20:18 +0000</pubDate>
		<dc:creator>manuel aldana</dc:creator>
				<category><![CDATA[Technologies/Tools]]></category>
		<category><![CDATA[clearcase not good]]></category>

		<guid isPermaLink="false">http://www.aldana-online.de/?p=128</guid>
		<description><![CDATA[After 3 years of working with ClearCase SCM tool I came to the point that you should not use it for developing software. Surely it has its moments: The branching and merging capabilities are good and the graphical version tree is nice. Also the concept of the config-spec, which is a kind of query-language for [...]]]></description>
			<content:encoded><![CDATA[<p>After 3 years of working with ClearCase SCM tool I came to the point that you should not use it for developing software. Surely it has its moments: The branching and merging capabilities are good and the graphical version tree is nice. Also the concept of the config-spec, which is a kind of query-language for an scm-configuration (the set of checked out artifacts) is powerful. But there also many shootout reasons, why it is bad.</p>
<h3>No atomic commits</h3>
<p>Once you checked in files it is very hard to revert to a certain state, because atomic commits aren&#8217;t supported. When checking in multiple files, each file gets a new revision (similar to CVS) and not the check-in itself. I think this is a crucial feature, because you hardly want revert single files but complete commit actions (which should map tasks). With ClearCase you can only revert to certain states by using Labels. In practice using ClearCase Labels for each check-in is overkill and thus not done.</p>
<h3>Crappy user interface</h3>
<p>The GUI of ClearCase Explorer is just a big joke. Horrible in usability and ugly looking. Different and often necessary functions aren&#8217;t provided (e.g. recursively checking in worked on artifacts). Command line tool cleartool used with cygwin is much better, but still some things aren&#8217;t available like recursively adding new files/folders to source control. I have to laugh my head off if I read a 50 lines of code long <a href=" http://www.ibm.com/developerworks/rational/library/4687.html#N10283" target="_blank">script</a> to workaround this.</p>
<h3>High administration efforts</h3>
<p>Administrating ClearCase beast is far from obvious or lightweight (in difference to other scm-systems like CVS, subversion or Git). Expect to put quite a few dedicated ClearCase experts to just keep it running.</p>
<h3>Horrible performance</h3>
<p>Nothing is worse as making your developers wait while interfacing with SCM-tool, it is like driving with hand brakes enabled. It slows down your brain and also your work. Getting fresh new files to your snapshot view takes around 30 minutes for 10K artifacts. An update (no artifacts were changed) for the same amount takes roughly 5 minutes. When experimenting a lot and jumping between different up-to-date views means a lot of waiting. It gets even worse, when you&#8217;re working on files and you want to check-in or update them. Check-out, check-in and adding to source control cycles take around 10-15 seconds which is obviously a nightmare. It gets very annoying when you&#8217;re refactoring renaming/moving types or methods (many files can be affected).</p>
<h3>Lack of support of distributed development</h3>
<p>Today software development is often a distributed thing (developers are spread around the world working on the same product/project). ClearCase definetely isn&#8217;t suitable for this,  because it is badly suited for offline work. Doing a check-out (action before you can edit  a file/folder) requires that you are network connected. Here you could use the hijack option but  this is rather a workaround as a feature (you basically just unlock the file on the filesystem). If your development sites are far away from your ClearCase server the check-in/check-out latency can even increase so dramatically that it is not usable at all. There are workarounds for that like using ClearCase Multisite (scm DB replica technology), but you have to pay extra for it and is not trivial to adminstrate.</p>
<h3>Git as alternative</h3>
<p>Though being a big fan+supporter of Open Source I am still willing to pay money for good software. But looking at IBM-monster ClearCase I wouldn&#8217;t invest my money here, it has all these discussed shortcomings, and further more IBM doesn&#8217;t seem to invest money to improve their product significantly. Recently I had a look a <a href="http://git-scm.com/" target="_blank">Git</a> scm which looks very good, especially for its branching+merging features, where ClearCase has its major strengths.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aldana-online.de/2009/03/19/reasons-why-you-should-stay-away-from-clearcase/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Continous code improvement with IntelliJ scm-integration</title>
		<link>http://www.aldana-online.de/2009/02/18/continous-code-improvement-with-intellij/</link>
		<comments>http://www.aldana-online.de/2009/02/18/continous-code-improvement-with-intellij/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 00:21:37 +0000</pubDate>
		<dc:creator>manuel aldana</dc:creator>
				<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Technologies/Tools]]></category>
		<category><![CDATA[code inspections]]></category>
		<category><![CDATA[code quality]]></category>
		<category><![CDATA[intellij]]></category>
		<category><![CDATA[scm]]></category>

		<guid isPermaLink="false">http://www.aldana-online.de/?p=124</guid>
		<description><![CDATA[As software engineers we get overwhelmed by the masses of bad-quality source code we work with each day. At this stage improvement of all these source code artifacts is a never ending story. To tackle this problem IntelliJ IDE goes the step-by-step improvement approach, where it runs actions and includes its powerfull code inspections on [...]]]></description>
			<content:encoded><![CDATA[<p>As software engineers we get overwhelmed by the masses of bad-quality source code we work with each day. At this stage improvement of all these source code artifacts is a never ending story. To tackle this problem IntelliJ IDE goes the step-by-step improvement approach, where it runs actions and includes its powerfull code inspections on your changes you are about to propagate to source control repository.<br />
<span id="more-124"></span></p>
<h3>Code quality issue</h3>
<p>Code gets written and as it changes (in most cases) it rottens also. In many projects/products changing and adding functionality  means having a larger codebase. And the bigger it gets the more difficult it becomes to improve the overall code quality picture:</p>
<ul>
<li>Motivation of developers decreases to keep code clean. In the end code gets worse and worse, just have a look<br />
at the &#8216;Broken windows&#8217; chapter of &#8216;The Pragmatic Programmer&#8217; for details</li>
<li>Efforts to clean up increases, more code needs to be maintained. Even if we are highly motivated to write &#8216;good&#8217; code, it is often difficult to know where to start.</li>
</ul>
<h3>Solution: Improve what you change</h3>
<p>There are two ways to tackle the problem: Big Bang or continous code improval. With BigBang you dedicate armies of developers who touch code just for the sake of making the code &#8216;better&#8217;. This approach has its drawbacks: You still don&#8217;t know where to start, it is difficult to sell to the product owners (feature stop) and further more it gets really boring (ever tried to tidy up your flat for a whole week without doing anything else?). An approach which worked better for team members and me was to introduce a kind of continous code improvement. It is important not to say that we get from 10000 warnings to 0, but to make a commitment that the warnings never ever get higher and must decrease after constantly. Here you improve your code quality in parallel to feature development and you only improve what you change. This much better sells to the product owner, you even don&#8217;t need to mention it, because it is part of your daily effort and should be transparent for non-techies.<br />
Furhter more incremental work-items can be managed better and focusing on certain artifacts also reduces overall efforts. In my view the best &#8220;quality-gate&#8221; for such an improve-what-you-change workflow is the source control commit or checkin phase. You changed code and now you want to ensure that checked-in sources provide a certain code-quality level.</p>
<p>Source control dialog IntelliJ:</p>
<p style="text-align: center;"><img class="size-full wp-image-126" title="commit-phase" src="http://www.aldana-online.de/wp-content/uploads/2009/02/commit-phase.png" alt="" width="500" height="451" /></p>
<h3>IntelliJ approach to continous code quality improvement</h3>
<p>The real problem is the tooling support: Humans are very bad at automating repeatable tasks. For instance when I am using Eclipse IDE and commiting sources to for instance Subversion, I often forget to reformat source code, remove unused imports or am just overlooking bad code snippets. IntelliJ (tested on version 8.1) goes a much better way: It provides actions (auto-formatting, auto-importing) while commiting and besides that can run static code analysis. For this code analysis it includes the so called &#8216;Inspections&#8217;, which are numerous and sensible (<a href="http://www.jetbrains.com/idea/features/code_inspection.html" target="_blank"></a>). For some cases it even provides an automated correction of the code flaw and the corresponding code snippet (pressing Alt+Enter). All these actions and checks are performed for the items you are about to commit only. This way IntelliJ mandates the successful approach to improve what you change or touch.</p>
<p>Dialog to review inspections and inspection results after pressing &#8216;Review button&#8217; :<br />
<img class="alignnone size-medium wp-image-125 alignleft" style="float: left;" title="checkresult" src="http://www.aldana-online.de/wp-content/uploads/2009/02/checkresult.png" alt="" width="265" height="140" /><br />
<img class="size-full wp-image-127" title="resultdetails" src="http://www.aldana-online.de/wp-content/uploads/2009/02/resultdetails.png" alt="" width="500" height="285" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.aldana-online.de/2009/02/18/continous-code-improvement-with-intellij/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting rid of checked exceptions in Java</title>
		<link>http://www.aldana-online.de/2008/07/28/getting-rid-of-checked-exceptions-in-java/</link>
		<comments>http://www.aldana-online.de/2008/07/28/getting-rid-of-checked-exceptions-in-java/#comments</comments>
		<pubDate>Mon, 28 Jul 2008 00:34:35 +0000</pubDate>
		<dc:creator>manuel aldana</dc:creator>
				<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://www.aldana-online.de/?p=123</guid>
		<description><![CDATA[Exception constructs in modern languages have replaced the way to map an error condition by a return value (like for instance in C). If used properly analyzation of error conditions and their handling can be performed very well. Never the less in Java, the so called checked exceptions are annoying since long (as a side [...]]]></description>
			<content:encoded><![CDATA[<p>Exception constructs in modern languages have replaced the way to map an error condition by a return value (like for instance in C). If used properly analyzation of error conditions and their handling can be performed very well. Never the less in Java, the so called checked exceptions are annoying since long (as a side note: C# seemed to have learned from this early language-design mistake because it supports unchecked exceptions only). This article discusses further why checked exceptions should be avoided.</p>
<p>This topic was already <a href="http://www.mindview.net/Etc/Discussions/CheckedExceptions" target="_blank">discussed</a> by clever Bruce Eckel, who is also thinking that checked exceptions aren&#8217;t such a good idea. To his reasoning one thing I would like to add is the &#8220;blurry assumption of api-interface&#8221; problem.</p>
<h3>Anticipation of incoming dependencies not possible</h3>
<p>Officially <a href="http://java.sun.com/docs/books/tutorial/essential/exceptions/runtime.html">Sun mentions</a> that checked exceptions should be used in case of &#8220;expected&#8221; exceptions, where clients still could react. In contrast unchecked exception should be used if programming erros occur, where a reaction is hardly possible (e.g. NullPointerException,  AssertionError).</p>
<p>In case of checked exception client code can decide whether to react to it directly (try/catch) or to delegate and pass it in the throws clause. In practice many checked exceptions aren&#8217;t interesting to client code, therefore you start to pass it to the throws clause. After a while spreading exceptions between different class-collaborations they are getting piled up and code-distraction is king and developers are constantly typing irrelevant code.</p>
<p>I&#8217;ve often seen code where developers got fed up with this pass-through of exceptions, workarounded this  with a bad exception handling coding style. So, in theory checked exceptions should increase code quality but in practice I perceived the opposite. This is bad, because a programming language design should help you to write good code and not constrain your work. Following workaround code snippets are quite common:</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw2">try</span><span class="br0">&#123;</span><br />
&nbsp; &#8230;<br />
<span class="br0">&#125;</span><span class="kw2">catch</span><span class="br0">&#40;</span>AnyCheckedException ace<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; <span class="co1">//no handling code</span><br />
&nbsp; <span class="co1">//swallowed away nirvana exception</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>Above is evil: Though exception should somehow be reported in lower area of method call stack, this try/catch just makes any error handling impossible. Such &#8220;nirvana&#8221; exceptions can make your life  really hard when locating defects.</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw2">try</span><span class="br0">&#123;</span><br />
&nbsp; &#8230;<br />
<span class="br0">&#125;</span><span class="kw2">catch</span><span class="br0">&#40;</span>AnyCheckedException ace<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; <span class="kw2">throw</span> <span class="kw2">new</span> <a href="http://www.google.com/search?q=allinurl%3ARuntimeException+java.sun.com&#038;bntl=1"><span class="kw3">RuntimeException</span></a><span class="br0">&#40;</span><span class="st0">&#8220;Error I don&#8217;t know what to do with. Got fed up with<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throws clause in all my method declarations!&#8221;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></div>
</div>
<p>Problem is that above newly thrown RuntimeException is too general and analyzation of certain error-conditions is hard. Often the causing checked exception isn&#8217;t even passed to the RuntimeException constructor so finding the root cause of a failure is also difficult.</p>
<p>To summarize: If client code cannot handle the exception, in practice checked exceptions aren&#8217;t passed to throws clause of method declaration. Indeed you can get really crazy if you need to pass the exception the whole method call-stack. Especially when doing bigger refactorings such millions of checked exceptions in the throws declarations are extremely annoying. Looking at this shortcoming developers often go for an improper exception handling. The difficulty of api-designers is that they cannot anticipate the exception-interpretation of incoming dependencies and thus the use of a checked exception can lead to bad exception handling code. They just don&#8217;t know, if a handling of an exception makes sense or not, see following examples:</p>
<h4><u>Example checked IOException</u></h4>
<p><strong>Trigger:</strong> IOException from java.io api gets thrown because a file under given pathname cannot be found.<br />
<strong>Handling appropriate:</strong> My client-code represents a file system manager, where I am searching for a file. The information &#8220;File not found&#8221; is directly relevant and file system manager could proceed to look in other directories.<br />
<strong>Handling not appropriate:</strong> I got a general app, where a property file should be loaded. Then the app should crash early/instantly, most likely I set a wrong path (Programming error).</p>
<h4><u>Example checked RemoteException</u></h4>
<p><strong>Trigger:</strong> RemoteException gets thrown, because network connection for RMI communication is broken.<br />
<strong>Handling appropriate:</strong> My client-code is a network monitoring tool and such information should be logged down for server downtime analyzation. Thus exception should be directly handled.<br />
<strong>Handling not appropriate:</strong> I got two application components which are communicating with RMI. The defect is a misconfiguration of the firewall. Application itself cannot react on this, it is a plain network setup defect.</p>
<p>Now Sun&#8217;s exception convention gets into problems: They told that Programming-Errors should always be mapped to unchecked exceptions&#8230; As shown above this does not work out, in some contexts the root cause of IOException is a Programming error (property-file loading) in some not (file-manager).</p>
<h3>Way out of checked exceptions</h3>
<p>Most likely Java standard won&#8217;t change this exception design-flaw, especially for backward compatibility reasons. But there is still a solution: When you are forced to handle checked exceptions constantly you can wrap them in custom unchecked exceptions (-&gt; extending an own custom exception hierachy from RuntimeException). This way other client code does not need to bother to look at non-interesting exception. The implication of mentioned points could also be that your api-design should only offer unchecked exceptions in method declarations.</p>
<p>Following this clients are not distracted by always doing this try/catch duet and code further more gets much better readable. Of course you should not just shove all checked exceptions directly into a RuntimeException (one of the workaround I explained above), you should be more concrete and build up a deeper exception type-hierachy to make further handling easier. Besides you should chain checked exception and pass it to the unchecked exception&#8217;s constructor to later find out root causes better.</p>
<p>Of course at one point such unchecked exceptions need to be handled at the outmost layer latest to make a proper report possible (e.g notifying monitoring/logging, sending back a user-friendly error HTML-message). You really don&#8217;t want to spill the whole stack-trace to a HTML or SOAP response or make your application to completely always shutdown.</p>
<h3>Conclusion</h3>
<p>Java introduced checked exceptions, which seemed to be a good idea in the first place to enforce clients to &#8220;have to know&#8221; about certain error conditions. But in practice developers do not pass &#8220;uninteresting&#8221; exceptions in throws clause, because code gets crowded and diffult to understand. They merely tend to workaround with inappropraite exception handling. Further more the view on exceptions, wheter they are worth the be catched or not, is context based and cannot be anticipated. To avoid this problem api-designers or client code generally should go for unchecked exception and a custom unchecked exception type-hierachy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aldana-online.de/2008/07/28/getting-rid-of-checked-exceptions-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
