<?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 Klimek &#187; Programming</title>
	<atom:link href="http://klimek.box4.net/blog/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://klimek.box4.net/blog</link>
	<description>Dedicated to Software Development</description>
	<lastBuildDate>Wed, 01 Jul 2009 20:23:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Review: Rapid Development</title>
		<link>http://klimek.box4.net/blog/2009/07/01/review-rapid-development/</link>
		<comments>http://klimek.box4.net/blog/2009/07/01/review-rapid-development/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 20:23:35 +0000</pubDate>
		<dc:creator>klimek</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://klimek.box4.net/blog/?p=108</guid>
		<description><![CDATA[I just finished reading Steve McConnell&#8217;s Rapid Development: Taming Wild Software Schedules. Well, many times it was not exactly &#8220;reading&#8221;, more like &#8220;page-skipping&#8221;. Obvious. Obvious. Obvious. But every time I thought I knew what was coming there was something unexpected hidden inside this big recapitulation of Fred Brook&#8217;s findings. With big hard data pictures on [...]]]></description>
			<content:encoded><![CDATA[<p><img style="float:left" src="http://ecx.images-amazon.com/images/I/41+sSYBlD9L._SL160_.jpg" alt="Rapid Development Cover" />I just finished reading Steve McConnell&#8217;s <a href="http://klimek.box4.net/blog/index.php?now_reading_author=steve-mcconnell&#038;now_reading_title=rapid-development-taming-wild-software-schedules">Rapid Development: Taming Wild Software Schedules</a>. Well, many times it was not exactly &#8220;reading&#8221;, more like &#8220;page-skipping&#8221;. Obvious. Obvious. Obvious. But every time I thought I knew what was coming there was something unexpected hidden inside this big recapitulation of Fred Brook&#8217;s findings. With big hard data pictures on the border. And then I&#8217;m horrified that I can relate to most of what is written, and that nothing&#8217;s really new to me any more. Even if I didn&#8217;t expect to read it from McConnell.</p>
<p>So the excitement of the days when I wrote stuff like <a href="http://klimek.box4.net/blog/2007/02/19/do-you-understand-xp/">Do You Understand XP?</a> is gone. Rapid Development is a good book that reviews every practice it preaches with a critical eye, but I&#8217;m not overly excited. Yes, I learned, again, that many so-called Agile practices are known for a long time. But hey, I knew that after reading the Mythical Man Month. Excitement is hard to find in books these days. If I only could find one of those thought-provoking books, that rips your universe apart.</p>
]]></content:encoded>
			<wfw:commentRss>http://klimek.box4.net/blog/2009/07/01/review-rapid-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>All Programmers Are Code Narcissists</title>
		<link>http://klimek.box4.net/blog/2009/06/07/all-programmers-are-code-narcissists/</link>
		<comments>http://klimek.box4.net/blog/2009/06/07/all-programmers-are-code-narcissists/#comments</comments>
		<pubDate>Sat, 06 Jun 2009 22:05:45 +0000</pubDate>
		<dc:creator>klimek</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://klimek.box4.net/blog/?p=106</guid>
		<description><![CDATA[01001101011110010010000001100011011011110110010001100101
00100000011100100111010101101100011001010111101000100001
I finally discovered the truth about why developers rather rewrite a 1MLOC project from scratch than trying to understand a fellow programmer&#8217;s code:
We&#8217;re all code narcissists!
And the reason for that can easily deducted in a tiny logical chain:
(The best code is easy to understand) ^ (I can understand my own code the easiest, duh!)
=> (My [...]]]></description>
			<content:encoded><![CDATA[<p>01001101011110010010000001100011011011110110010001100101<br />
00100000011100100111010101101100011001010111101000100001</p>
<p>I finally discovered the truth about why developers rather rewrite a 1MLOC project from scratch than trying to understand a fellow programmer&#8217;s code:</p>
<p><b>We&#8217;re all code narcissists!</b></p>
<p>And the reason for that can easily deducted in a tiny logical chain:<br />
<em>(The best code is easy to understand) ^ (I can understand my own code the easiest, duh!)<br />
=> (My own code is the best code)</em></p>
<p>Unfortunately this is only true for me, or perfect clones of myself. Which rules out everybody else I work with. Which reminds me&#8230; What was the reason that programming is done in teams?</p>
]]></content:encoded>
			<wfw:commentRss>http://klimek.box4.net/blog/2009/06/07/all-programmers-are-code-narcissists/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Test Everything That Could Possibly Break &#8211; A Guide To Better Testing</title>
		<link>http://klimek.box4.net/blog/2009/02/09/test-everything-that-could-possibly-break-a-guide-to-better-testing/</link>
		<comments>http://klimek.box4.net/blog/2009/02/09/test-everything-that-could-possibly-break-a-guide-to-better-testing/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 04:43:28 +0000</pubDate>
		<dc:creator>klimek</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://klimek.box4.net/blog/?p=105</guid>
		<description><![CDATA[Joe: &#8220;Writing this test will make sure that we find bugs quicker. It will let us change the code without breaking anything and it will help us to write decoupled code.&#8221;
Jim: &#8220;Maintaining this test will be a nightmare. It is tightly coupled to the class we&#8217;re writing and we cannot change anything without changing the [...]]]></description>
			<content:encoded><![CDATA[<p>Joe: &#8220;Writing this test will make sure that we find bugs quicker. It will let us change the code without breaking anything and it will help us to write decoupled code.&#8221;<br />
Jim: &#8220;Maintaining this test will be a nightmare. It is tightly coupled to the class we&#8217;re writing and we cannot change anything without changing the test. It will be a pain.&#8221;<br />
Joe: &#8220;How do you know?&#8221;<br />
Jim: &#8220;Well, how do <em>you</em> know?&#8221;<br />
Joe: &#8220;I have 20 years of experience not writing unit tests.&#8221;</p>
<p><strong>So what?</strong><br />
When I&#8217;m writing new code I am never sure whether I test enough, or if my tests are on the right level of abstraction. For complicated core functionality of a distributed system this is a no-brainer &#8211; I use TDD, which by the very definition gives me 100% code coverage, and add some nice integration and acceptance tests. But there are a myriad of cases where going forward in the baby-step TDD way seems a waste of time, and it would really help me to find some sensible rules to apply.</p>
<p>The simplest and best rule I have found so far is an idea from Extreme Programming:<br />
<strong>Test Everything That Could Possibly Break</strong></p>
<p>Unfortunately this rule is not as simple as it looks. My approach to that is the good old mantra of <em>try-measure-adapt</em>, where <em>try</em> means to just do whatever a randomly selected guy thinks is the new cool-aid, <em>measure</em> means to listen to that whimsical thoughts my brain produces while doing it and <em>adapt</em> means to look at the results and change my behavior.</p>
<p>So here&#8217;s my guide to better testing, from the beginner to the professional level:</p>
<p><strong>Beginner:</strong> Do some unimportant project by following <a href="http://klimek.box4.net/blog/index.php?now_reading_author=kent-beck&#038;now_reading_title=test-driven-development-by-example-addison-wesley-signature-series">the description of TDD</a> step-by-step. Don&#8217;t waste your employers money with that if you don&#8217;t have any idea of how to do it &#8211; the first time you use it will be a disaster. Writing yet another Sudoku solver in your favorite programming language might be a cool idea.<br />
The important part is that you don&#8217;t have an idea of what &#8220;test everything that could possibly break&#8221; means, so your best bet is to assume everything might break. Even those getters and setters over there. Remember that you&#8217;re not allowed to rant about made-up scenarios of why too many tests might be bad if you have never experienced what it means to maintain a program with too many tests. Do that first and come back later and read on.</p>
<p><strong>Advanced:</strong> So you already have some experience doing TDD and know how it feels to write all those little unit tests. You got some feedback on when those tests caught a stupid bug that would have taken an hour to find if you hadn&#8217;t written the test. You now know what the impact of unit tests on your ability to do refactorings is. Now go and break the rules by various degrees. Try to be less exhaustive with your tests and bundle your baby steps into bigger units of work. See how that affects your ability to find bugs. Test your assumptions and be aware of when they break. When you find a new bug that takes some hours to debug, think about what kind of test would have helped you find it quicker and write those tests from now on.</p>
<p><strong>Expert:</strong> If I were an expert I could probably tell you more about what to do in that case. I still hope that repeating the advanced guidelines will finally make me as wise as <a href="http://joelonsoftware.com/items/2009/01/31.html">Joel and Jeff in their discussions</a> or <a href="http://java.dzone.com/articles/thoughts-developer-testing">Jay Fields when he writes about developer tests</a>. Perhaps listening to those guys will enlighten you. You could even take a look at the very interesting discussion of the idea to <a href="http://c2.com/cgi-bin/wiki?TestEverythingThatCouldPossiblyBreak">test everything that could possibly break</a>.</p>
<p>In a nutshell:</p>
<ul>
<li>Start by testing everything, even if it looks stupid (don&#8217;t do it at work).</li>
<li>Do slightly bigger steps and see what happens.</li>
<li>Adapt whenever you experience a situation in which different behavior would have made more sense.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://klimek.box4.net/blog/2009/02/09/test-everything-that-could-possibly-break-a-guide-to-better-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Leaving the Comfort Zone</title>
		<link>http://klimek.box4.net/blog/2008/12/22/leaving-the-comfort-zone/</link>
		<comments>http://klimek.box4.net/blog/2008/12/22/leaving-the-comfort-zone/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 21:02:43 +0000</pubDate>
		<dc:creator>klimek</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://klimek.box4.net/blog/?p=104</guid>
		<description><![CDATA[A week ago I held my first talk since university. It was the first talk in my life I held in English, and I was scared like hell. It felt like living through those exam days back at school all over again &#8211; just that this time I thought I&#8217;m old enough to realize that [...]]]></description>
			<content:encoded><![CDATA[<p>A week ago I held my first talk since university. It was the first talk in my life I held in English, and I was scared like hell. It felt like living through those exam days back at school all over again &#8211; just that this time I thought I&#8217;m old enough to realize that it&#8217;ll all be okay. I&#8217;m obviously not.</p>
<p>I acted just like I did back in school. Or worse. I waited for the last possible moment before I started preparing the talk. When I finally started with the slides, a little perfectionist devil Manuel sat down leisurely on my left shoulder, telling me that this crap is just not up to my own standards. I worked long hours the night before the big day, and woke up early just to be able to rehearse the whole play before entering the stage.</p>
<p>Of course everything worked out just fine. Well, besides me saying basic-a-lly all the time. So why was I so freaked out? Well, I was obviously leaving my comfort zone.</p>
<p>Now the interesting thing beneath all that personal drama I&#8217;m ranting about is that I suddenly realized for how long I did not really step out of my safe little comfort zone. Granted, applying at Google is not the most un-stressful experience I ever had. And obviously starting a new job with all those bright people around me did not exactly make me fell warm and cozy.</p>
<p>But at that very moment I stood there, my peers gazing absent-mindedly into their laptops, my hands slightly sweating, I suddenly realized that ever since I started working I was doing everything exactly in the way I was most comfortable with. And that was kind of a shock.</p>
<p>Of course after giving the talk I felt great. I had known that in advance, but I realized that without being nudged enough I&#8217;d probably have tried to wiggle out somehow. </p>
<p>Lessons learned:</p>
<ol>
<li>It&#8217;s easier to step out of the comfort zone when somebody kicks your ass.</li>
<li>It&#8217;s a long way from leaving your comfort zone once to <a href="http://www.ibm.com/developerworks/rational/library/nov07/pollice/index.html">real change</a>.</li>
<li>I must learn how to leave my comfort zone on my own.</li>
</ol>
<p>Do you know tricks that make it easier to leave the comfort zone?</p>
]]></content:encoded>
			<wfw:commentRss>http://klimek.box4.net/blog/2008/12/22/leaving-the-comfort-zone/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>An Editor Independent Unittest Executor</title>
		<link>http://klimek.box4.net/blog/2008/03/11/an-editor-independent-unittest-executor/</link>
		<comments>http://klimek.box4.net/blog/2008/03/11/an-editor-independent-unittest-executor/#comments</comments>
		<pubDate>Tue, 11 Mar 2008 21:46:25 +0000</pubDate>
		<dc:creator>klimek</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://klimek.box4.net/blog/2008/03/11/an-editor-independent-unittest-executor/</guid>
		<description><![CDATA[Since I got test infected I&#8217;m somehow unable to write a single line of untested code without feeling uneasy. When I just want to write a tiny script containing a few lines of code in whatever text editor is installed in a system, it seems to be a daunting task to set up a programming [...]]]></description>
			<content:encoded><![CDATA[<p>Since I got test infected I&#8217;m somehow unable to write a single line of untested code <a href="http://klimek.box4.net/blog/2007/11/01/fasten-your-seat-belts-chances-and-pitfalls-of-test-driving-your-development/">without feeling uneasy</a>. When I just want to write a tiny script containing a few lines of code in whatever text editor is installed in a system, it seems to be a daunting task to set up a programming environment that allows you to execute unit tests with a single click. But this single click is what makes writing unit tests unobtrusive enough to keep doing it.</p>
<p>So I&#8217;m quite fond of using a simple script to execute my script&#8217;s unit tests whenever I save it. This concept is not new, and certainly not an original idea in itself, but the simplicity of an editor independent unit test executor in 10 lines of code has a certain appeal for me:</p>
<pre class="code">
#!/bin/bash
stat_command="stat -c '%Y'"
file_name=$1
last_modification=""
while true; do
  current_modification=$( $stat_command $file_name )
  if [ "$current_modification" != "$last_modification" ]; then
    clear
    $file_name --test
    last_modification=$current_modification
  fi
  sleep 1
done
</pre>
<p>This script stats the script file until it detects a change. Whenever a change is detected, the script is called with <i>&#8211;test</i>, which is my personal way to tell a script that it should just execute it&#8217;s unit tests and exit. See my blog post about <a href="http://klimek.box4.net/blog/2008/02/04/integrating-unit-tests-in-ruby-scripts/">integrating unit tests in Ruby scripts</a> to learn how this can be done in Ruby. A very similar approach is possible for Python:</p>
<pre class="code">
#!/usr/bin/python
import unittest
import sys

if sys.argv.count("--test") > 0:
  sys.argv.remove("--test")
  unittest.main()
</pre>
<p>Now I can simply call the test bash script, giving it the script under test as parameter:</p>
<pre class="code">
./run_tests.sh ./script_under_test.py
</pre>
<p>The beauty lies in the simplicity of the solution: Even when I remote edit a script on some server with vi, I can simply launch a new console and execute run_tests.sh, watching the test results whenever I type &#8220;:w&#8221;. </p>
<p><b>Update: The &#8220;sleep 1&#8243; really helps to keep I/O load down. Thanks to Philip for pointing this out. And yet another nice example of how hard it is to write 10 lines of bugfree code without a test.</b></p>
]]></content:encoded>
			<wfw:commentRss>http://klimek.box4.net/blog/2008/03/11/an-editor-independent-unittest-executor/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Integrating Unit Tests In Ruby Scripts</title>
		<link>http://klimek.box4.net/blog/2008/02/04/integrating-unit-tests-in-ruby-scripts/</link>
		<comments>http://klimek.box4.net/blog/2008/02/04/integrating-unit-tests-in-ruby-scripts/#comments</comments>
		<pubDate>Mon, 04 Feb 2008 21:21:30 +0000</pubDate>
		<dc:creator>klimek</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://klimek.box4.net/blog/2008/02/04/integrating-unit-tests-in-ruby-scripts/</guid>
		<description><![CDATA[When I write ruby scripts I like to use a single file, containing the program and all unit tests. It took me some time to find out how to add a command line switch to my ruby scripts that makes them run in script mode with full access to the Test::Unit command line arguments, while [...]]]></description>
			<content:encoded><![CDATA[<p>When I write ruby scripts I like to use a single file, containing the program and all unit tests. It took me some time to find out how to add a command line switch to my ruby scripts that makes them run in script mode with full access to the Test::Unit command line arguments, while being able to run the script without the test framework interfering in the execution:</p>
<pre class="code">
#!/usr/bin/ruby -w
require 'test/unit'

if ARGV.include?("--test")
  ARGV.delete_at(ARGV.index("--test"))
else
  Test::Unit::run = true
  puts "Running..."
end
</pre>
<p>Now you can simply run the program by typing</p>
<pre class="code">
$ ./testme.rb
Running...
</pre>
<p>or run the tests with</p>
<pre class="code">
$ ./testme.rb --test
Loaded suite ./testme
Started

Finished in 0.0 seconds.

0 tests, 0 assertions, 0 failures, 0 errors
</pre>
<p>The nice thing is that only the first &#8220;&#8211;test&#8221; will be removed, so you can still leverage the Test::Unit command line argument interface.</p>
]]></content:encoded>
			<wfw:commentRss>http://klimek.box4.net/blog/2008/02/04/integrating-unit-tests-in-ruby-scripts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>My First OCaml Tests &#8211; So Close To Heaven!</title>
		<link>http://klimek.box4.net/blog/2007/12/26/my-first-ocaml-tests-so-close-to-heaven/</link>
		<comments>http://klimek.box4.net/blog/2007/12/26/my-first-ocaml-tests-so-close-to-heaven/#comments</comments>
		<pubDate>Tue, 25 Dec 2007 23:19:04 +0000</pubDate>
		<dc:creator>klimek</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://klimek.box4.net/blog/2007/12/26/my-first-ocaml-tests-so-close-to-heaven/</guid>
		<description><![CDATA[Some time ago a a discussion in the testdrivendevelopment Yahoo-Group evolved around the concept of &#8220;testable languages&#8221;. I thought about this for a while and came up with the idea that I want to be able to have expressions as first class citizens:

assertThat { assertThat(false) } abortsWith TestFailedException

Today I played a little with OCaml, sorted [...]]]></description>
			<content:encoded><![CDATA[<p>Some time ago a a discussion in the testdrivendevelopment Yahoo-Group evolved around the concept of <a href="http://tech.groups.yahoo.com/group/testdrivendevelopment/message/26384">&#8220;testable languages&#8221;</a>. I thought about this for a while and came up with the idea that I want to be able to have <a href="http://tech.groups.yahoo.com/group/testdrivendevelopment/message/26424">expressions as first class citizens</a>:</p>
<pre class="code">
assertThat { assertThat(false) } abortsWith TestFailedException
</pre>
<p>Today I played a little with <a href="http://caml.inria.fr/ocaml/">OCaml</a>, sorted my functional programming skillz out, and finally arrived at my first test driven unit test environment for OCaml! Note that it&#8217;s nearly what I wanted to be able to write, but unfortunately there&#8217;s not enough syntactic sugar for lambda expressions (or I didn&#8217;t find out, yet), so I&#8217;m stuck with using the quite ugly ( function () -> expression ) syntax. But hey, it&#8217;s really close to heaven.</p>
<pre class="code">
exception TestFailed
exception TestError

let failsWith expectedError expression =
	try
		expression ();
		false
	with error ->
		expectedError = error

let isTrue expression: bool =
	expression

let isFalse expression: bool =
	not (expression)

let assertThat expression conditionMatchesOn =
	if not (conditionMatchesOn (expression)) then
		raise TestFailed
	else
		()

let _ = (
	assertThat true isTrue;
	assertThat (isTrue true) isTrue;
	assertThat (not (isTrue false)) isTrue;

	assertThat false isFalse;
	assertThat (isFalse false) isTrue;

	assertThat (TestFailed = TestFailed) isTrue;
	assertThat (failsWith TestError (function () -> raise TestError)) isTrue;
	assertThat (failsWith TestFailed (function () -> raise TestError)) isFalse;
	assertThat
		( function () -> assertThat false isTrue )
		( failsWith TestFailed );

	Printf.printf "OK\n";
);;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://klimek.box4.net/blog/2007/12/26/my-first-ocaml-tests-so-close-to-heaven/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Does &#8220;Test After&#8221; Work For You?</title>
		<link>http://klimek.box4.net/blog/2007/11/17/does-test-after-work-for-you/</link>
		<comments>http://klimek.box4.net/blog/2007/11/17/does-test-after-work-for-you/#comments</comments>
		<pubDate>Fri, 16 Nov 2007 22:26:29 +0000</pubDate>
		<dc:creator>klimek</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://klimek.box4.net/blog/2007/11/17/does-test-after-work-for-you/</guid>
		<description><![CDATA[&#8220;Why not write a test for this?&#8221;
&#8220;Why should I, it works&#8230;&#8221;
The idea of Test-After Development is to write a set of automated white-box tests after writing your production code. Since probably every CS student in the world has learned that unit tests are a good idea, you&#8217;d expect unit testing to be an industry state [...]]]></description>
			<content:encoded><![CDATA[<p>&#8220;Why not write a test for this?&#8221;<br />
&#8220;Why should I, it works&#8230;&#8221;</p>
<p>The idea of Test-After Development is to write a set of automated white-box tests after writing your production code. Since probably every CS student in the world has learned that unit tests are a good idea, you&#8217;d expect unit testing to be an industry state standard for quite a while now. Interestingly the idea of automated unit and integration test is lately becoming more popular due to the widespread use of Test-Driven Development.</p>
<p>So why do we need Test-Driven Development to be able to efficiently write automated unit tests?</p>
<ul>
<li>If you write your code first and don&#8217;t think about how to test the code, the code will not be testable. Thus testing becomes expensive and frustrating. Test-Driven Development will guide your software design by the old mantra of &#8220;how-do-I-want-to-use-this-class&#8221;, leading to a highly decoupled design.</li>
<li>When you write your tests, you&#8217;ll discover a lot of errors. But instead of the red bar in Test-Driven Development, which you <em>expect</em>, the red bar in Test-After Development is the demotivating sword of reality.</li>
<li>The most important reason why I have never seen Test-After Development work, is that developers just don&#8217;t believe in errors once they wrote the code. This seems to be an eternal wisdom of software development psychology: once the code works, why bother testing it? Let&#8217;s just implement the next feature.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://klimek.box4.net/blog/2007/11/17/does-test-after-work-for-you/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Fasten Your Seat Belts! &#8211; Chances And Pitfalls Of Test Driving Your Development</title>
		<link>http://klimek.box4.net/blog/2007/11/01/fasten-your-seat-belts-chances-and-pitfalls-of-test-driving-your-development/</link>
		<comments>http://klimek.box4.net/blog/2007/11/01/fasten-your-seat-belts-chances-and-pitfalls-of-test-driving-your-development/#comments</comments>
		<pubDate>Wed, 31 Oct 2007 22:32:23 +0000</pubDate>
		<dc:creator>klimek</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://klimek.box4.net/blog/2007/11/01/fasten-your-seat-belts-chances-and-pitfalls-of-test-driving-your-development/</guid>
		<description><![CDATA[Ten years ago I had a rendezvous with a beautiful girl, and at the end of the evening I gave her a ride home. Back than I thought playing the gentleman to be posh, so I opened the door for her. She slid with one elegant movement into her seat and I paced around the [...]]]></description>
			<content:encoded><![CDATA[<p>Ten years ago I had a rendezvous with a beautiful girl, and at the end of the evening I gave her a ride home. Back than I thought playing the gentleman to be posh, so I opened the door for her. She slid with one elegant movement into her seat and I paced around the car and folded my wiry frame behind the steering wheel. I looked at her.</p>
<p>&#8220;Don&#8217;t you want to start?&#8221;, she asked and watched me curiously. &#8220;Um&#8221;, I said, obviously always finding the right words at the right moment. &#8220;Um. &#8211; Not before you buckle up&#8230;&#8221;. She frowned at me: &#8220;But I never buckle up&#8221;. I replied &#8220;Well, if you don&#8217;t buckle up, we&#8217;re not gonna go anywhere tonight&#8221;. &#8220;Oh come on!&#8221;, she now somewhat furiously stated. &#8220;Nope!&#8221; I insisted eloquently, finally feeling her shield of stubborn resistance falter. It took a few seconds before she realized that I really wouldn&#8217;t drive her home without her being properly protected from falling through the windshield and decomposing her pretty head by hitting the next best fireplug. So she buckled up.</p>
<p>Even back than I was so used to the secure feeling of the protective belt that just thinking of driving unbelted drove an uneasy quiver through my guts. This feeling is so strong that if I don&#8217;t drive strapped when moving the car just a few inches there&#8217;s always a sense of awareness that makes me want to fasten the seat belt immediately.</p>
<p>Today I felt exactly the same way while writing code.</p>
<h3>The path of the test</h3>
<p>At the beginning of the last iteration we identified a story that affected some legacy modules in our code base. When we recognized that the changes we needed to make would touch more code than we had thought, so we decided to try to test drive a part of the system from scratch to replace the tangled old code. So Richard, Reinhard and myself started to pair on the story alternately. Besides some private experiments with a Sudoku solver in Java this was the first time I was doing real full time TDD pair programming for a couple of days. Aside from some initial irritation and the constant realization that pair programming is hard to learn I was quickly pulled into the red-green-refactor cycle, as usual. But this time I held the pace for longer than ever. And was pulled into the cycle deeper and deeper. Write a test, make it work, look for redundancy. Write a test, make it work, look for redundancy. Write a test&#8230;</p>
<p>Today I wanted to quickly integrate the changed interface into an existing module. I didn&#8217;t have a test yet. The cpp file was readily opened in my editor. Just a quick edit, nothing more than integrating this interface. A few simple edits. Only three lines or something. And suddenly a nagging question materializing in my head:</p>
<p><b>How can I make sure this works?</b></p>
<p>At this moment I felt like driving unbuckled. I felt unsafe. I wanted my cozy safety net back. Like an addict I went for the next test.</p>
<h3>What use is a seat belt when you hit a tree at 200 MPH?</h3>
<p>Since I&#8217;m the one driving the adoption of XP in our company, I wanted to try TDD for myself on a save playground to learn more about the ins and outs before applying it at work. Since Java has really nice tools for TDD, I started test driving a small Sudoku solver in Java. This was my first real test driven code and I often wondered about how nicely the test suite covered my errors. Spirited in the Agile fashion, I began with a really straight forward brute force implementation. Everything went a lot more smoothly than I had expected and after some coding I had a simple solution that needed over 90 seconds for one simple Sudoku.</p>
<p>After a while I wanted to optimize the runtime. So I introduced some caching variables. I struggled with the failing tests as my solution grew more and more sophisticated, but the tests helped me to get to a deeper understanding of the real problem. Finally I arrived at a point where the algorithm managed to work through 1400 Sudokus in less than a second. I was thrilled. And I wanted more. So I installed a profiling framework to find out where the next optimization sweet spot would be hidden. When I browsed the profiling data I realized that the real solver didn&#8217;t even <em>call</em> the algorithm. So I had benchmarked a program that didn&#8217;t solve any Sudoku at all.</p>
<p><b>At this moment I felt like hitting a tree with 200 MPH, suddenly realizing that it is not a good idea to drive that fast into a 90-degree turn on a wet street, even if you have a seat belt.</b></p>
<p>After the blood had returned to my head on it&#8217;s way to my brain I implemented a test into the main program to check every solution with a simple algorithm before claiming to have solved anything. In the meantime I have a solution that runs 1400 Sudokus in 6 seconds on my core 2 notebook. I&#8217;m even quite convinced that I got the solution part correct&#8230;</p>
<h3>Do I get my driver&#8217;s license?</h3>
<p>So, here&#8217;s the lesson I learned on this journey on my path to the test:</p>
<ul>
<li><b>Don&#8217;t rely on your tests too quickly.</b><br />
If you want to heed the XP advice to &#8220;test everything that can possibly break&#8221;, be aware that it&#8217;s often the things of which you think that they can&#8217;t break that finally break.
</li>
<li><b>Use a healthy mixture of tests on all abstraction levels.</b><br />
Unit and functional tests are orthogonal &#8211; they cover different aspects of the code. But of course you&#8217;ll already have a lot of unit <em>and</em> functional tests if you don&#8217;t rely on your tests too quickly.
</li>
<li><b>Buckle up!</b><br />
The unsafe feeling while trying to modify code without having a test was a very impressive experience for me. I know that from now on I&#8217;ll fasten my code&#8217;s seat belt.
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://klimek.box4.net/blog/2007/11/01/fasten-your-seat-belts-chances-and-pitfalls-of-test-driving-your-development/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Can You Remember Hungarian TLAs?</title>
		<link>http://klimek.box4.net/blog/2007/10/29/can-you-remember-hungarian-tlas/</link>
		<comments>http://klimek.box4.net/blog/2007/10/29/can-you-remember-hungarian-tlas/#comments</comments>
		<pubDate>Mon, 29 Oct 2007 21:03:43 +0000</pubDate>
		<dc:creator>klimek</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://klimek.box4.net/blog/2007/10/29/can-you-remember-hungarian-tlas/</guid>
		<description><![CDATA[Scene 1. Karl and J.B. are pairing on a small web service. Karl is just returning to the workplace with a steaming, hot cup of coffee in his hand.
Karl: &#8216;Let me see what you wrote just now&#8230; 
usUserName = request.getParameter("UserName");
Um&#8230; This variable, usUserName, what does the us-prefix stand for?&#8217;
J.B.: &#8216;Well, that is the unescaped user [...]]]></description>
			<content:encoded><![CDATA[<p><b>Scene 1.</b> Karl and J.B. are pairing on a small web service. Karl is just returning to the workplace with a steaming, hot cup of coffee in his hand.</p>
<p><b>Karl:</b> &#8216;Let me see what you wrote just now&#8230; </p>
<pre class="code">usUserName = request.getParameter("UserName");</pre>
<p>Um&#8230; This variable, usUserName, what does the <em>us</em>-prefix stand for?&#8217;<br />
<b>J.B.:</b> &#8216;Well, that is the unescaped user name the way we get it from the user. I wanted to make sure that we don&#8217;t accidentally write it into a database or send it back in it&#8217;s evil, unescaped form to the webbrowser. If we use the us-prefix every time we have an unsafe string, we&#8217;ll immediately recognize any error that could otherwise escape us because we will learn to look for such errors. This is the application Hungarian notation I read about over at <a href="http://www.joelonsoftware.com/articles/Wrong.html">Joel&#8217;s site</a>, where you actually use a prefix that has a meaning instead of just a shorthand for the type.&#8217;<br />
<b>Karl:</b> &#8216;So&#8230; why not just call it <em>unescapedUserName</em>?&#8217;</p>
<h3>Confusion</h3>
<p>In a time where you enter veryLongVariableNames by typing &#8216;v&#8217;, &#8216;e&#8217;, &#8216;r&#8217;, Crtl-Space, I don&#8217;t see why we can&#8217;t finally get rid of <a href="http://en.wikipedia.org/wiki/Three-letter_acronym">TLAs</a>. You know that the Hungarian notation got out of hand when your colleagues check in code that changes ucpBuffer to pucBuffer (&#8221;fixed a segfault&#8221;). Why not just name a variable for what it contains, in plain old English? I definitely know that I should think about my method name if my partner asks during a pairing session: &#8220;And what exactly do you intend to do in this method?&#8221;.</p>
<p>In which example is the error easier to spot? Does the second example really take longer to write? To read? To understand?</p>
<pre class="code">
for(unsigned int i = 0; i < iLineCount(); ++i)
{
  for(unsigned int j = 0; j < iNodeCount(i); ++i)
  {
    pGetNode(i, j)->layout();
  }
}
</pre>
<pre class="code">
for(unsigned int lineIndex = 0;lineIndex < getLineCount(); ++lineIndex)
{
  for(unsigned int nodeIndex = 0; nodeIndex < getNodeCount(lineIndex); ++lineIndex)
  {
    getNode(lineIndex, nodeIndex)->layout();
  }
}
</pre>
<p>If you can really remember mnemonic prefix TLAs (or any TLAs for that matter) and think Hungarian notation or abbrVarNames are a great way to safe yourself some typing, please let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://klimek.box4.net/blog/2007/10/29/can-you-remember-hungarian-tlas/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
