<?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>Schauderhaft &#187; Softwaredevelopment</title>
	<atom:link href="http://blog.schauderhaft.de/category/softwaredevelopment/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.schauderhaft.de</link>
	<description>Softwaredevelopment, Projectmanagement, Qualitymanagement and all things &#34;schauderhaft&#34;</description>
	<lastBuildDate>Sun, 22 Jan 2012 19:13:43 +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>Fixing the Singleton</title>
		<link>http://blog.schauderhaft.de/2012/01/22/fixing-the-singleton/</link>
		<comments>http://blog.schauderhaft.de/2012/01/22/fixing-the-singleton/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 19:13:43 +0000</pubDate>
		<dc:creator>Jens Schauder</dc:creator>
				<category><![CDATA[Softwaredevelopment]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[pattern]]></category>
		<category><![CDATA[singleton]]></category>

		<guid isPermaLink="false">http://blog.schauderhaft.de/?p=1024</guid>
		<description><![CDATA[When you ask people who know almost, but not completely nothing about patterns, about software design patterns, they probably bring up the singleton pattern. It&#8217;s extremely easy: Just make sure you have one single instance of a class. If you ask more experienced developers about the singleton, they will probably tell you its bad and [...]]]></description>
			<content:encoded><![CDATA[<p>When you ask people who know almost, but not completely nothing about patterns, about software design patterns, they probably bring up the singleton pattern. It&#8217;s extremely easy: Just make sure you have one single instance of a class.</p>
<p>If you ask more experienced developers about the singleton, they will probably tell you its bad and should be avoided.</p>
<p>What is so bad about the singleton that it fell from the heavon of patterns into the hell of anti patterns?</p>
<p>If you check the description of the singleton pattern in the <a href="http://www.amazon.de/gp/product/0201633612?ie=UTF8&amp;tag=schauderhafte-21&amp;linkCode=shr&amp;camp=3206&amp;creative=21426&amp;creativeASIN=0201633612&amp;ref_=sr_1_1&amp;qid=1326657640&amp;sr=8-1">Gang of Four book</a> it talks about two characteristics of the singleton:</p>
<ul>
<li>There can be only  a single instance</li>
<li>There is a central access point to that instance</li>
</ul>
<p>And there really is nothing wrong about the first point. Sometimes you really can&#8217;t have more then one instance, but even if multiple instances don&#8217;t hurt, if they don&#8217;t give you any benefit (i.e. if they are stateless) you might as well reuse a single instance.</p>
<p>The problem is really with the central access point. This makes the singleton look and behave like a global variable. And how should we obtain our dependencies? Correct through Dependency injection.</p>
<p>So the next time you think: &#8220;Looks like a singleton to me&#8221;. Go ahead, create a singleton. But also create an interface which gets implemented by the singleton and make it very clear that nobody may use this singleton except via its interface and <a href="/2012/01/01/the-one-correct-way-to-do-dependency-injection/">dependency injection through constructor</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.schauderhaft.de/2012/01/22/fixing-the-singleton/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Tips for Testing Database Code</title>
		<link>http://blog.schauderhaft.de/2012/01/15/tipps-for-testing-database-code/</link>
		<comments>http://blog.schauderhaft.de/2012/01/15/tipps-for-testing-database-code/#comments</comments>
		<pubDate>Sun, 15 Jan 2012 05:52:33 +0000</pubDate>
		<dc:creator>Jens Schauder</dc:creator>
				<category><![CDATA[Softwaredevelopment]]></category>
		<category><![CDATA[continuous integration]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://blog.schauderhaft.de/?p=1013</guid>
		<description><![CDATA[Almost everybody understands that source code belongs into version control. Many people understand we need to test our code. Quite a few do that automatically. But everything seems to change when it comes to databases. A lot of stuff in and around databases goes untested. Heck some of the scripts don&#8217;t even live in version [...]]]></description>
			<content:encoded><![CDATA[<p>Almost everybody understands that source code belongs into version control. Many people understand we need to test our code. Quite a few do that automatically.</p>
<p>But everything seems to change when it comes to databases. A lot of stuff in and around databases goes untested. Heck some of the scripts don&#8217;t even live in version control. If you can&#8217;t believe that, because you haven&#8217;t seen it, you are a damn lucky bastard.</p>
<p>At least one reason for this state of affairs is obviously: It hurts. Database tests tend to be slow, interdependent and hard to maintain. Granted. But you know what: If it hurts, you should do it more often. It will teach you what exactly the things are that cause pain when testing and eventually you&#8217;ll find approaches to make it less painful. Here are some ideas I found helpful when testing database related code:</p>
<ul>
<li>Give every developer her own database. This forces you to find a way to set up the database fast, easy and reliable. If your application lives in a single user/schema/namespace it is sufficient for each developer to have his own user/schema/namespace in a single database. For this to work though &#8230;</li>
<li>&#8230; the application should be user/schema/namespace agnostic. It makes it much easier to create multiple instances one a single server.</li>
<li>Let the application live in a single user/schema/namespace. If you have multiple interdependent namespaces (e.g. for modules) you&#8217;ll have a hard time making them agnostic of the names.</li>
<li> Have separate instances for CI, Demos, QA and so on. Actually ideally it should be trivial to create a fresh instance.</li>
<li>Stay away from any tool that comes with its own repository. If have seen about a dozen of such tools and although some looked promising in the beginning, they all completely failed to integrate with other tools on the development side of things. Examples of such tools are tools for code generation from <a href="http://en.wikipedia.org/wiki/Unified_Modeling_Language">UML</a> or <a href="http://en.wikipedia.org/wiki/Entity-relationship_model">ER</a> models and <a href="http://en.wikipedia.org/wiki/Extract,_transform,_load">ETL</a> tools.</li>
</ul>
<p>The previous points where about the setup of your database and infrastructure. Lets have a look at the code:</p>
<ul>
<li> Favor a proper Language (like Java, C, PHP &#8230;) over database specific languages like T-SQL or PL/SQL. If you are wondering why, make a comparison between your favorite DB language and your all purpose language. For which do you get the better IDE, Unit testing support, code analysis, code coverage and so on. Reconsider your main language if it doesn&#8217;t win in that comparison.</li>
<li> Have a small layer that does all interaction with the database. Make sure no SQL or other database dependent code leaks out. Inject that layer as a dependency into anybody in need of it. This will allow you to test almost everything without worrying about the database. Only the tests for that integration layer actually needs a database for testing.</li>
<li>Favor database independent SQL or a library abstracting away the differences of various databases. Back in the time people claimed they needed that in case they have to switch database vendors, which never happened. Now it does. See below.</li>
</ul>
<p>The next points will deal with the actual tests:</p>
<ul>
<li>Consider an in-memory-database for testing. Many databases can run in an in-memory-mode. They are great for testing, because you can throw them away after the test, and they are way faster then any database writing to disk. This of course is only possible when you work with a database system that can run as a in-memory-database or if your code is database independent. Hence the previous point.</li>
<li>If you can&#8217;t use your database as in memory database, consider putting it on a RAM disk. We got a huge performance gain for our tests with this approach. A solid state disk might be the next best thing although I&#8217;m not sure how it would react to the heavy load of continuous database tests.</li>
<li>Make test failure messages so explicit that you don&#8217;t have to look into the database for analyzing test failures.</li>
<li>Use code for setting up your test data. Make it nice and concise. If you need a row in a table without special requirements for its values you should be able to create that with a single trivial line of code, no matter how many foreign keys the table contains. I.e. you should have a little <a href="/2011/03/20/testing-databases-with-junit-and-hibernate-part-2-the-mother-of-all-things/">DSL for your test data</a>. Doing it with plain code will enable all the refactoring power of your IDE for your tests. For load and performance tests other approaches like loading production data or large amounts of generated data might be suitable.</li>
<li>Make sure your tests clean up after them selves. There are two approaches I found usable in most cases:</li>
</ul>
<blockquote>
<ol>
<li>Recreate the schema for every test. This is slow but really safe.</li>
<li>Do a rollback after each test. This only works when there is no commit inside the test. The mean thing is: If a test tries to rollback, but fails because there was a commit inside the test some completely different test will fail. It can be a really frustrating task to find the bad test in such a case.</li>
</ol>
</blockquote>
<p>We covered the testing of  database related code inside your application. But there is another kind of code we need to deal with: Scripts for deploying your application (or upgrading it)</p>
<ul>
<li>The scripts that change your database schema from one version to the next are source code just like everything else. Therefore they belong under version control and should get tested continuously.</li>
<li>The testing process is really simple: Create a database as it looks now. Apply your change scripts and verify it looks as desired.</li>
<li>For verifying the resulting schema it is useful to have a script that creates your target database (or at least the schema) from scratch, so you compare it with the result of the test.</li>
<li>For performance reasons you might want to test this with an empty database first.</li>
<li>But don&#8217;t forget to run it on an instance with realistic data as well. Hint: adding a column to huge tables can take loooooong.</li>
</ul>
<p>Happy testing everybody.</p>
<blockquote><p>&nbsp;</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.schauderhaft.de/2012/01/15/tipps-for-testing-database-code/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>The Right Amount of Up-Front Design?</title>
		<link>http://blog.schauderhaft.de/2012/01/12/the-right-amount-of-up-front-design/</link>
		<comments>http://blog.schauderhaft.de/2012/01/12/the-right-amount-of-up-front-design/#comments</comments>
		<pubDate>Thu, 12 Jan 2012 13:13:04 +0000</pubDate>
		<dc:creator>Jens Schauder</dc:creator>
				<category><![CDATA[Softwaredevelopment]]></category>
		<category><![CDATA[design]]></category>

		<guid isPermaLink="false">http://blog.schauderhaft.de/?p=1019</guid>
		<description><![CDATA[Maybe its just because I&#8217;m following Simon Brown on twitter, but I saw a phrase like &#8220;just the right amount up-front design&#8221; often enough to make me think. Am I doing the right amount of up-front design? I never before thought about this question in my software projects. But I also hardly ever had the [...]]]></description>
			<content:encoded><![CDATA[<p>Maybe its just because I&#8217;m following <a href="https://twitter.com/#!/simonbrown">Simon Brown</a> on twitter, but I saw a phrase like &#8220;just the right amount up-front design&#8221; often enough to make me think.</p>
<p><strong>Am I doing the right amount of up-front design?</strong></p>
<p>I never before thought about this question in my software projects. But I also hardly ever had the feeling of &#8220;damn we did to much or to little of it back then&#8221;. How can this be possible? The reason might be that in some sense my approach to hitting the sweet spot for the amount of design is extremely easy:</p>
<p><strong>Design as much as possible, as early as possible! But not more or earlier!</strong></p>
<p>So some people might imagine me now sitting for weeks in a row working with UML tools and hammering out diagrams and design documents. Nothing could be farther from the truth. The key is in the interpretation of  when design is possible. For me design is all about solving a problem. So in order to do some designing one needs a problem. If you have found a problem do as much design for it as possible. &#8216;much&#8217; doesn&#8217;t get measured in hours or number of pages or diagrams. &#8216;much&#8217; gets measured in the extend to which the problem gets solved. If you can design a solution that makes a problem go away. Great! If you only find one that makes it a tiny problem: It will have to do until you find a better solution.</p>
<p>But now we are stuck with trying to find a better solution for a not completely solved problem, right? Wrong! In reality we have lots of problems in a project, so we pick the worst one whip up the solution, until the next problem is bigger then the first.</p>
<p>So if you are spending time with a problem that isn&#8217;t the most pressing one, you are doing to much up-front design. But everybody would immediately stop doing it once he realizes it, right? If on the other hand you are knowingly ignoring your biggest problem you are doing to little up-front design. But the more common name for this is sabotage.</p>
<p>Of course it does happen that what you thought is a great solution turns out as a bad idea, or that you just can&#8217;t find a solution for a especially bad problem, or a problem jumps at you from behind. Congratulations you found the border of your skills. Its an opportunity to learn an to train you problem identification or solving skills. It is not the time to decide, I should do more of it (or less) next time.</p>
<p>It really is a simple process. Yet software design is considered difficult. So where is the difficult part?</p>
<p>There are actually three difficult parts:</p>
<ul>
<li>Seeing the problems as early as possible, so you can solve them while they are small</li>
<li>Finding good solutions fast.</li>
<li>Having a great team that understands that every software developer is a software designer</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.schauderhaft.de/2012/01/12/the-right-amount-of-up-front-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The One Correct Way to do Dependency Injection</title>
		<link>http://blog.schauderhaft.de/2012/01/01/the-one-correct-way-to-do-dependency-injection/</link>
		<comments>http://blog.schauderhaft.de/2012/01/01/the-one-correct-way-to-do-dependency-injection/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 05:17:02 +0000</pubDate>
		<dc:creator>Jens Schauder</dc:creator>
				<category><![CDATA[Softwaredevelopment]]></category>
		<category><![CDATA[clean code]]></category>
		<category><![CDATA[dependency injection]]></category>

		<guid isPermaLink="false">http://blog.schauderhaft.de/?p=996</guid>
		<description><![CDATA[A couple of weeks ago a coworker told me that they have a little utility in their projects in order to set private fields for tests. He kind of claimed they needed that since they are using Spring, which in production sets the dependency. I was a little confused. But after looking into it I [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of weeks ago a coworker told me that they have a little utility in their projects in order to set private fields for tests. He kind of claimed they needed that since they are using Spring, which in production sets the dependency. I was a little confused. But after looking into it I realized that there is an (anti)pattern going on that needs some fighting against. Lets have a look at the pattern.</p>
<p>Spring (and other DI frameworks) can inject dependencies into private fields. It looks like people like to use this because it combines some compelling properties:</p>
<ul>
<li>Very little boilerplate code. All you need is a simple annotation on the field.</li>
<li>Since the field is private nobody outside the class can change it.</li>
</ul>
<p>But now when you want to test your class and want to assign e.g. a mock to the field you have to either setup a Spring context in your tests or use reflection in order to access the field (just as Spring does).</p>
<p>Now something is really starting to smell bad here. One of the purposes of Dependency Injection is to decouple code, which in turn should make the code easier to test. Now that didn&#8217;t work out to well.</p>
<p>So how can we clean up this mess? We can write a setter for the field. That solves the testing problem. It adds a little boiler plate code, but hey we are talking Java here, so you should be used to that. But now we have a setter which anybody can call at any time. At the very best that doesn&#8217;t make any sense at all in the production environment. In the worst case somebody actually uses it and creates some ugly bug.</p>
<p>So what do you do when you don&#8217;t want anybody to change a field? Correct you make it final. Great, now you have a compile time error in the setter.You can only set a final field in a constructor. This leads naturally to the solution of all our problems (and possibly to world peace): <strong>Make your dependency a constructor argument!</strong></p>
<p>This is the only place where dependencies really belong. If you try to stick to that rule I&#8217;d expect you&#8217;ll encounter the following two problems.</p>
<ol>
<li>You&#8217;ll find classes with lots and lots of constructor arguments. I&#8217;ll bet that class does a lot of different things and really needs to get broken down into smaller pieces.</li>
<li>You&#8217;ll find cases where a class A needs an instance of B and B needs an instance of  A. This is a typical case of a circular dependency and is obviously bad. In my experience the solution is either to make B a part of A when the two are so strongly dependent that they really should be one class. More often though there is at least one more class C hiding in there so that B doesn&#8217;t need A but only C.</li>
</ol>
<p>So really the problems you&#8217;ll find when doing constructor based dependency injection are problems that are present in your current code already. So don&#8217;t shoot the messenger, but fix the problems in your code and go for constructor arguments for dependency injection.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.schauderhaft.de/2012/01/01/the-one-correct-way-to-do-dependency-injection/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>The second D in TDD</title>
		<link>http://blog.schauderhaft.de/2011/12/25/the-second-d-in-tdd/</link>
		<comments>http://blog.schauderhaft.de/2011/12/25/the-second-d-in-tdd/#comments</comments>
		<pubDate>Sun, 25 Dec 2011 12:14:51 +0000</pubDate>
		<dc:creator>Jens Schauder</dc:creator>
				<category><![CDATA[Softwaredevelopment]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://blog.schauderhaft.de/?p=990</guid>
		<description><![CDATA[Some proponents of TDD say, that TDD forces you to find a good design. Some even translate TDD to Test Driven Design. I don&#8217;t agree. Mostly. Lets start with the small part where I do agree. Since TDD forces you to write test first, it forces you to think about how you want to use [...]]]></description>
			<content:encoded><![CDATA[<p>Some proponents of TDD say, that TDD forces you to find a good design. Some even translate TDD to Test Driven Design. I don&#8217;t agree. Mostly.</p>
<p>Lets start with the small part where I do agree.</p>
<p>Since TDD forces you to write test first, it forces you to think about how you want to use an API, because that is the very first thing you write down. This is a good thing and in my case led to more usable APIs (often in the form of Builders or little internal DSLs).</p>
<p>Since it is almost insane to test anything if it isn&#8217;t properly decoupled from stuff it uses, TDD also forces you to factor out dependencies in order to be able to mock them. Thats the other point where TDD encourages good design.</p>
<p>But there are bad news: There is more to software design than just nice to use APIs and SOLID principles: Your design actually has to solve a problem! And TDD does almost nothing for you in order to find a good solution for your problem. Yet this is really the hard part in software design.</p>
<p>Can your domain model represent all the cases needed by the business? TDD won&#8217;t tell you.</p>
<p>Should represent some edge cases of the domain in a &#8216;dirty&#8217; way and thereby making the domain model simpler and therefor 99% of the use cases way easier? Or should you go for the complete but awfully complex solution? TDD won&#8217;t tell you.</p>
<p>Which of all the design patterns would help you? Or is there some well known algorithm you could use to solve your problem? TDD won&#8217;t tell you.</p>
<p>Does the problem become trivial once you approach it in a functional way? TDD won&#8217;t tell you.</p>
<p>Is recursion a solution or a dead end? TDD won&#8217;t tell you.</p>
<p>You have to understand the problem and know lots of possible approaches to a problem in order to design software well. There is just no way around it.</p>
<p>Once you have the solution in your mind, once you know the basic data structures and algorithm you going to use, TDD will help you to implement it in a clean, well factored way. It will also help you to stay focused on the task at hand (which is making the next test green).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.schauderhaft.de/2011/12/25/the-second-d-in-tdd/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Sketch and Test</title>
		<link>http://blog.schauderhaft.de/2011/12/18/sketch-and-test/</link>
		<comments>http://blog.schauderhaft.de/2011/12/18/sketch-and-test/#comments</comments>
		<pubDate>Sun, 18 Dec 2011 05:39:26 +0000</pubDate>
		<dc:creator>Jens Schauder</dc:creator>
				<category><![CDATA[Softwaredevelopment]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[process]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://blog.schauderhaft.de/?p=983</guid>
		<description><![CDATA[I try to do TDD as much as I can. But sometimes (for example last Friday) I don&#8217;t know how to get started. This happens when I don&#8217;t have a plan of how the code should look in the end, possibly because don&#8217;t completely understand part of the problem. Especially I didn&#8217;t know how I [...]]]></description>
			<content:encoded><![CDATA[<p>I try to do TDD as much as I can. But sometimes (for example last Friday) I don&#8217;t know how to get started. This happens when I don&#8217;t have a plan of how the code should look in the end, possibly because don&#8217;t completely understand part of the problem. Especially I didn&#8217;t know how I would be able to test it, due to the fact it the code had to interact with a different system and a database.</p>
<p>The <a href="http://www.amazon.de/gp/product/020161622X?ie=UTF8&#038;tag=schauderhafte-21&#038;linkCode=shr&#038;camp=3206&#038;creative=21426&#038;creativeASIN=020161622X&#038;ref_=sr_1_1&#038;qid=1324160771&#038;sr=8-1">pragmatic programmer</a> recommends a tracer bullet or spike in this case. This means you implement some kind of prototype in order to clarify how to implement it properly. </p>
<p>And than you throw that away and implement it properly again, which for me means test driven.</p>
<p>Do you really do that? For me this goes against the principle of baby steps and of refactoring instead of rewriting code. </p>
<p>Also I was fearing it wouldn&#8217;t help much, because the problem wasn&#8217;t so much that I was unclear about the code, but about how to test it.</p>
<p>So last Friday I tried a different approach. I call it &#8216;Sketch and Test&#8217; </p>
<p>I started by implementing the complete thing in one single class. Without tests (scary, I know). But I never actually executed the code. I just wrote it as I thought it should work. </p>
<p>Once this <strong>sketch</strong> was finished I looked at the code and considered the changes I needed to make in order to test it. </p>
<p>I did the changes and finally created the tests, fixing the bugs I found in the progress.</p>
<p>Only when all the tests where in place and green I actually started the application and tested the new feature. </p>
<p>It worked, i.e. the feature did what I expected. The code qualifies as clean and I had complete code coverage with the only exception of some weird exception handling code, that I found hard to trigger in tests.</p>
<p>What do you think? Is this a viable approach? Or is it just a symptom of my limited TDD skills? Or both?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.schauderhaft.de/2011/12/18/sketch-and-test/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>My Testing and Code Analysis Toolbox</title>
		<link>http://blog.schauderhaft.de/2011/12/11/my-testing-and-code-analysis-toolbox/</link>
		<comments>http://blog.schauderhaft.de/2011/12/11/my-testing-and-code-analysis-toolbox/#comments</comments>
		<pubDate>Sun, 11 Dec 2011 06:39:00 +0000</pubDate>
		<dc:creator>Jens Schauder</dc:creator>
				<category><![CDATA[Softwaredevelopment]]></category>
		<category><![CDATA[code analysis]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[quality]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://blog.schauderhaft.de/?p=980</guid>
		<description><![CDATA[Last week we kicked of a &#8220;Testing Skill Group&#8221; at LINEAS, a group for exchanging knowledge about testing. One question that came up over and over again in various flavors was: What tools are there for testing and analyzing your code? So here is my personal answer for this, in the approximately order I tend [...]]]></description>
			<content:encoded><![CDATA[<p>Last week we kicked of a &#8220;Testing Skill Group&#8221; at <a href="http://www.lineas.de/">LINEAS</a>, a group for exchanging knowledge about testing. One question that came up over and over again in various flavors was: What tools are there for testing and analyzing your code? So here is my personal answer for this, in the approximately order I tend to introduce them into projects:</p>
<p><a href="http://junit.org/">JUnit</a>: JUnit is pretty much the basis for everything else. Its THE unit testing framework for Java, with great integration in IDEs, build tools and CI Server. I don&#8217;t take the term &#8216;unit&#8217; to seriously though. I use JUnit to execute all other kinds of tests as well. </p>
<p><a href="http://code.google.com/p/mockito/">Mockito</a>: There are many Mocking Frameworks out there but I prefer this one. It has nice DSLish API and I find it nice to use. Only drawback is that in some special cases the standard API doesn&#8217;t work and one has to use an <a href="http://docs.mockito.googlecode.com/hg/latest/org/mockito/Mockito.html#12">alternative syntax</a>.</p>
<p><a href="http://code.google.com/p/powermock/">PowerMock</a>: I actually try not to introduce this into projects. You need PowerMock if you want to mock constructors, static or final methods. If you need this, PowerMock gets the job done, but its better not to need it.</p>
<p><a href="http://jenkins-ci.org/">Jenkins</a>: a free continuous integration server. Not exactly a work of beauty, but it works, is easy to setup and does everything I needed so far with the help of a couple of <a href="https://wiki.jenkins-ci.org/display/JENKINS/Plugins#Plugins-Pluginsbytopic">plugins</a>.</p>
<p><a href="http://checkstyle.sourceforge.net/">CheckStyle</a>: A static code analysis that finds lots of bad practices and can check lots of coding conventions too. Integrates in IDEs and CI server. There are other tools in this area which are worth considering: <a href="http://findbugs.sourceforge.net/">FindBugs </a>and <a href="http://pmd.sourceforge.net/">PMD</a>. You can also use Checkstyle in order to gather <a href="http://erik.doernenburg.com/2008/11/how-toxic-is-your-code/">simple metrics about your code</a>.</p>
<p><a href="http://clarkware.com/software/JDepend.html">JDepend</a>: does static code analysis of the dependencies of your code. I use it to write tests against cycles between packages in the code and also in order to limit the dependencies to those I&#8217;m willing to accept in the code base. Some time ago I found out there are some limitations in JDepend resulting in dependencies that JDepend misses (I think it doesn&#8217;t consider classes in annotations or something). Therefore I&#8217;m looking at <a href="http://depfind.sourceforge.net/">DependencyFinder</a>, which seems to be way more powerful, but is certainly harder to use. I actually build a little tool for <a href="https://github.com/schauder/Dependency-Manager">visualizing dependencies</a> based on DependencyFinder.</p>
<p><a href="http://cobertura.sourceforge.net/">Cobertura</a>/<a href="http://www.eclemma.org/">EclEmma</a>: Cobertura and <a href="http://emma.sourceforge.net/">Emma</a> are code coverage tools. I use them both. Emma in the form of EclEmma as an eclipse plugin and Cobertura in Jenkins, because we couldn&#8217;t get Emma to work as we wanted on our Jenkins instance.</p>
<p><a href="http://www.sonarsource.org/">Sonar</a>: It collects tons of metrics from your code and makes them available as a website. It actually to much numbers for my taste. In a serious project you can spend the whole day looking at numbers. What is really great about sonar is, that it tracks those numbers over time, so you can see if your average method length goes up or down over time. In some projects I configured a graph with the most important numbers plotted over time and added it to the main screen of Jenkins.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.schauderhaft.de/2011/12/11/my-testing-and-code-analysis-toolbox/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Three Types of Learning</title>
		<link>http://blog.schauderhaft.de/2011/12/04/three-types-of-learning/</link>
		<comments>http://blog.schauderhaft.de/2011/12/04/three-types-of-learning/#comments</comments>
		<pubDate>Sun, 04 Dec 2011 06:20:51 +0000</pubDate>
		<dc:creator>Jens Schauder</dc:creator>
				<category><![CDATA[Softwaredevelopment]]></category>
		<category><![CDATA[chess]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[practice]]></category>
		<category><![CDATA[theory]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://blog.schauderhaft.de/?p=975</guid>
		<description><![CDATA[My kids are playing chess. And they really eager to play it even better. Therefore I&#8217;m reading books about how to teach chess. Much of the advice in the book are really not that specialized on chess but are applicable for any kind of learning and training. One of those advices is: There are three [...]]]></description>
			<content:encoded><![CDATA[<p>My kids are playing chess. And they really eager to play it even better. Therefore I&#8217;m reading books about how to teach chess. Much of the advice in the book are really not that specialized on chess but are applicable for any kind of learning and training. One of those advices is: There are three kinds of training:</p>
<p><strong>Theory</strong>: Here kids learn about different patterns (yes there are patterns in chess just as there are in software development). They learn when and how to apply them. Mostly by looking at examples and analyzing them. They also learn rules, like how to properly convert a pawn into a queen if no queen is available (Hint: turning a rook upside down doesn&#8217;t work)</p>
<p><strong>Practice</strong>: In this kind of training the kids get isolated problems to solve. Puzzles basically. Like Mate in one. They also do games based on chess rules, but not actually chess. Like collecting gummy bear from the chess board with knights.</p>
<p><strong>Play</strong>: Starting from a friendly game against family or other club members to tournament.</p>
<p>I think it maps 1:1 to what you should do if you want to improve your software development skills:</p>
<p><strong>Theory</strong>: Read books, read blogs, go to conferences. Learn as much as you can about design, algorithms, network protocols and so on. 90% of all developers neglect this. But since you are already reading this blog, you are probably among the other 10%</p>
<p><strong>Practice</strong>: Do Katas, Dojos, spikes, tracer bullets, prototypes. Write code. But not in order to have working code in the hand but in order to learn and explore. I&#8217;m afraid 90% of those doing the theory part completely neglect this part. You should not. The first couple of times you try to use something which you have read or heard about, you probably will do it wrong. To bad if this is in a real project with time pressure and lots of money at risk.</p>
<p><strong>Work</strong>: If you take care of the first two parts work will still bring some surprises. Your agile approach runs into problems because the customer doesn&#8217;t like it. Your nicely normalized schema doesn&#8217;t happen because you have to use an old existing database, used by lots of other applications, what worked nicely in the kata fails flat on its face when applied to 1 million records &#8230; So there is still a lot of stuff you can learn at work, but for this you have to think about what you are doing at work. Chess players eager to improve their skills analyze games they played in order to understand which move was good and which wasn&#8217;t. Do you do that? Do you do a personal retrospective in the evening? Thinking what you did well? What you could have done better? </p>
<p>I think you should.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.schauderhaft.de/2011/12/04/three-types-of-learning/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>The Three Ways to Work with Code</title>
		<link>http://blog.schauderhaft.de/2011/11/27/the-three-ways-to-work-with-code/</link>
		<comments>http://blog.schauderhaft.de/2011/11/27/the-three-ways-to-work-with-code/#comments</comments>
		<pubDate>Sun, 27 Nov 2011 20:31:36 +0000</pubDate>
		<dc:creator>Jens Schauder</dc:creator>
				<category><![CDATA[Softwaredevelopment]]></category>
		<category><![CDATA[abstraction]]></category>
		<category><![CDATA[read code]]></category>
		<category><![CDATA[write code]]></category>

		<guid isPermaLink="false">http://blog.schauderhaft.de/?p=969</guid>
		<description><![CDATA[Obviously you read code more often than you write it. Nothing new here. This fact is brought up often when the need for clean code is discussed. Or when the merits of different programming languages are weighed. I think this two fold distinction is not sufficient. You write code. Thats fine. But when reading code, [...]]]></description>
			<content:encoded><![CDATA[<p>Obviously you read code more often than you write it. Nothing new here. This fact is brought up often when the need for clean code is discussed. Or when the merits of different programming languages are weighed.</p>
<p>I think this two fold distinction is not sufficient. You write code. Thats fine. But when reading code, there are actually two different kinds of reading. Lets start with an example:</p>
<div class="geshi no scala">
<ol>
<li class="li1">
<div class="de1">val string = &quot;Hello World&quot;
</div>
</li>
<li class="li1">
<div class="de1">string should startWith (&quot;Hello&quot;)</div>
</li>
</ol>
</div>
<p>Even if you didn&#8217;t follow my articles about <a href="http://blog.schauderhaft.de/2010/12/26/testing-with-scala/">ScalaTest</a> you can understand what this line of code is doing. In this sense reading this line of code is extremely easy. I call this &#8216;skimming&#8217;</p>
<p>But what if this line of code is not doing what you expected? Then you need to really understand the code. Then you want to understand what is going on. In the Scala example above you might consider the following options: Is <tt>startWith("Hello")</tt> a parameter to <tt>should</tt>? Or is <tt>"Hello"</tt> an argument passed to the result you get after passing <tt>startWith</tt> to <tt>should</tt>? What is <tt>should</tt> anyway? A method? An object? A function? An instance with <tt>apply</tt> method?</p>
<p>As you can see what was realy easy to skim now gets quite challenging to &#8216;understand&#8217;.</p>
<p>The same can be the case for libraries. Consider Hibernate. If you have setup Hibernate, CRUD operations on an entity are really easy to write and understand. But once you get one of the dreaded Hibernate exceptions (<a href="http://docs.jboss.org/hibernate/core/3.5/api/org/hibernate/LazyInitializationException.html">LazyInitializationException</a>, <a href="http://docs.jboss.org/hibernate/core/3.5/api/org/hibernate/NonUniqueObjectException.html">NonUniqueObjectException</a>, &#8230;) you want to really understand what is going on. And at that point many people realize they have no idea what is actually happening when they call <tt>session.update</tt> or just the getter of an Hibernate Proxy.</p>
<p>Obviously you want all three kinds of handling code to be as easy as possible, and writing might be the least important, because we read more code then we write. But how important is the ability to skim versus understanding?</p>
<p>With anything you use in an application you will do a lot of skimming. Thats why DSLs like the ScalaTest example above are such a great tool. </p>
<p>I suspect if you do complex things with a library or a language, understanding will always be hard. But in some cases it gets extra hard because non standard tricks are used. In Java a typical case of trick is Reflection and Byte Code Manipulation. Many of the more powerfull libraries use it to work around the limitations of &#8216;normal&#8217; Java. The result is code that is easy to skimm but for many people next to impossible to understand. Examples are Mockito or Hibernate. </p>
<p>So when evaluating a library or writing one you might consider how much magic it is using.</p>
<p>The other way to limit the problem with &#8216;understanding&#8217; code is to make it unessecary. I think Hibernate is an example where this failed. You have tons of places where you have to understand pretty exactly what Hibernate is doing in order to use it correctly. </p>
<p>Java itself is an example where this works pretty good. In many, many projects nobody has to actually understand how the JVM works. It just works. Only in rare cases you have to dive into the details of the garbage collector or the memory model.</p>
<p>The key here is a clean non <a href="http://www.joelonsoftware.com/articles/LeakyAbstractions.html">leaky abstraction</a>. If you have that it doesn&#8217;t matter what kind of magic you use to make it happen. But if your abstraction is leaky, parts of the magic you use inside will leak out with the risc of turning your project into something that acts like it is bewitched.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.schauderhaft.de/2011/11/27/the-three-ways-to-work-with-code/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Boiling Frog</title>
		<link>http://blog.schauderhaft.de/2011/11/13/the-boiling-frog/</link>
		<comments>http://blog.schauderhaft.de/2011/11/13/the-boiling-frog/#comments</comments>
		<pubDate>Sun, 13 Nov 2011 11:57:04 +0000</pubDate>
		<dc:creator>Jens Schauder</dc:creator>
				<category><![CDATA[Softwaredevelopment]]></category>
		<category><![CDATA[boiling frog]]></category>
		<category><![CDATA[clean code]]></category>
		<category><![CDATA[refactoring]]></category>
		<category><![CDATA[technical debt]]></category>

		<guid isPermaLink="false">http://blog.schauderhaft.de/?p=963</guid>
		<description><![CDATA[I hope everybody among my readers is familiar with the concept of technical debt: If you do a quick hack to implement a feature it might be faster to implement in the short run, but you have to pay interest for the technical debt in the form of higher development and maintenance effort. If you [...]]]></description>
			<content:encoded><![CDATA[<p>I hope everybody among my readers is familiar with the concept of technical debt: If you do a quick hack to implement a feature it might be faster to implement in the short run, but you have to pay interest for the technical debt in the form of higher development and maintenance effort. If you don&#8217;t pay back you technical debt by refactoring your code, sooner or later your quick hack will have turned in a quick and highly expensive hack.</p>
<p>This metaphor works well to communicate the need for refactorings if at least one person realized the need for it.</p>
<p>But in various cases nobody in the project realizes that there is a problem until the team face a huge debt which seems impossible to pay back.</p>
<p>I see two possible reasons:</p>
<p><strong>Being blind</strong>: There is a different level of cleanliness people consider clean enough. In interviews I have repeatedly talked to people considering a 20 line method a good thing and don&#8217;t have problem with nested control structures 5 levels deep. Those developers wouldn&#8217;t notice anything smelly when looking at code which I would consider CMD (Code of Mass Destruction). This problem is most of the time fairly easy to fix by teaching and coaching. But there is a more insidious possible reason:</p>
<p><strong>Being a frog in boiling water</strong>: There is a theory that a frog which sits in cold water doesn&#8217;t jump out of the water if you heat it realy slow until it dies.<a href="http://en.wikipedia.org/wiki/Boiling_frog"> Wikipedia isn&#8217;t decisive</a> if this is actually true, but I definetly see this effect in software development. It looks like this: At some point you find something in your code that looks like it has an easy abstraction. So you build a little class encapsulating that behaviour and use that class instead. It works great, so that little class gets used a lot. Sometime later the class gets a new feature to handle a variation of the original case. And it goes on like this, until one day what was a simple abstraction has turned in a complex library, possibly even a framework. And now that framework is a problem on its own. Its getting hard to understand how to use it.</p>
<p>And you realize you are a poor little frog sitting in boiling water with no idea how he got there. Hint: It&#8217;s a good idea to jump even when it is a little late.</p>
<p><strong>Why does this happen?</strong> Just as the frog has a problem sensing the small change in temperatur and realizing he is getting into trouble the developer doesn&#8217;t see he is hurting the quality of the code base until it is to late.</p>
<p><strong>Again: Why?</strong> Let&#8217;s make the example a little more specific. You have blocks of 10 lines of simple repetitive code in N places in your code base. You replace it with a call to a simple class of 40 lines of code. So you save (9*N &#8211; 40) lines. On the call site your code gets significantly simpler, of course the class is a little more complex but thats ok. Now while implementing a new feature you are about to create another of those 10 line blocks. Obviously you want to use the helper class. But it&#8217;s not fit for the job. You need to add a feature to it. That&#8217;s ok. You also have to add something to the public API to turn that feature on or of. Maybe it&#8217;s a new constructor, a new method or an additional parameter. That&#8217;s not ok. Until you changed the API of your class the changes where local to the helper class and its usage at the new site. But when you changed the API, you added complexity to all the call sites of your class. Whenever you now call that helper you have to think a little more about the correct API to use. This unfortunatly isn&#8217;t easy to see. So it can easily happen that your API turns slowly so complex that using it is more painfull then just writing the 10 lines it replaces down.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.schauderhaft.de/2011/11/13/the-boiling-frog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

