<?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/"
	>

<channel>
	<title>core-dump</title>
	<atom:link href="http://www.core-dump.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.core-dump.net</link>
	<description>about productivity, programming and stuff</description>
	<pubDate>Tue, 31 Mar 2009 09:44:18 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Powerful yet easy caching with OSCache</title>
		<link>http://www.core-dump.net/programming/powerful-yet-easy-caching-with-oscache/</link>
		<comments>http://www.core-dump.net/programming/powerful-yet-easy-caching-with-oscache/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 09:44:18 +0000</pubDate>
		<dc:creator>alex</dc:creator>
		
		<category><![CDATA[programming]]></category>

		<category><![CDATA[optimization]]></category>

		<category><![CDATA[performance]]></category>

		<category><![CDATA[tuning]]></category>

		<guid isPermaLink="false">http://www.core-dump.net/?p=77</guid>
		<description><![CDATA[In the last post I wrote about ways to tackle bottlenecks and to increase the performance of an application. When dealing with a high traffic application servicing tons of concurrent users all requesting the same data, intelligent caching can boost the speed in which requests are processed. As a result, lots of load is taken [...]]]></description>
			<content:encoded><![CDATA[<p>In the last post I wrote about ways to tackle bottlenecks and to increase the performance of an application. When dealing with a high traffic application servicing tons of concurrent users all requesting the same data, intelligent caching can boost the speed in which requests are processed. As a result, lots of load is taken away from the database.</p>
<p>Querying a database makes much sense when the data requested changes a lot. But imagine the database is backing a blog or news website where the data requested from the database is the same in hundreds or even thousands of cases. The most frequent query sent to the database in such an environment is probably for loading the article on page one, which - once published - probably won’t change a lot. This doesn’t hurt the Database if your private blog has 100 unique visitors per day, but if the frontpage of a popular news website is attacked by 100.000 unique visitors per hour then you are in trouble. You need to use caching in order to take away stress from your database server.</p>
<p>An excellent, widely used open source cache solution which is easy to use and yet powerful is OSCache (<a href="http://www.opensymphony.com/oscache/" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.opensymphony.com');" target="_blank">http://www.opensymphony.com/oscache/</a>). Besides features like clustering, a servlet filter for caching entire JSP pages or persistent caching it comes with a JSP tag library that enables you to include caching into your jsp based web application so easily it hurts.</p>
<p>All you have to do is:<br />
1)       Add the OSCache jar file to your classpath, put the tld file into the WEB-INF directory of the webapp and declare the OSCache taglib in your jsp page:</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="sc3"><span class="re1">&lt;jsp:root</span> <span class="re0">version</span>=<span class="st0">&quot;1.2&quot;</span> <span class="re0">xmlns:jsp</span>=<span class="st0">&quot;http://java.sun.com/JSP/Page&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span class="re0">xmlns:cms</span>=<span class="st0">&quot;cms-taglib&quot;</span> <span class="re0">xmlns:cmsu</span>=<span class="st0">&quot;cms-util-taglib&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span class="re0">xmlns:c</span>=<span class="st0">&quot;http://java.sun.com/jsp/jstl/core&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span class="re0">xmlns:fmt</span>=<span class="st0">&quot;http://java.sun.com/jsp/jstl/fmt&quot;</span><br />
&nbsp; &nbsp; <span class="re0">xmlns:cache</span>=<span class="st0">&quot;urn:jsptld:oscache.tld&quot;</span><span class="re2">&gt;</span></span></div>
</div>
<p>2)       mark portions of the jsp-page to be cached in your jsp page with cache tags:</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="sc3"><span class="re1">&lt;cache:cache</span> <span class="re0">key</span>=<span class="st0">&quot;${cacheKey}&quot;</span> <span class="re0">time</span>=<span class="st0">&quot;0&quot;</span> <span class="re0">language</span>=<span class="st0">&quot;${language}&quot;</span> <span class="re0">time</span>=”<span class="nu0">1800</span>”<span class="re2">&gt;</span></span><br />
Content to be cached<br />
<span class="sc3"><span class="re1">&lt;/cache:cache<span class="re2">&gt;</span></span></span></div>
</div>
<p>In this example the cached portion of the page is stored under the key defined in the variable cacheKey, it supports multiple languages and expires after 1800 seconds. There are a few other attributes available for configuring the cache tag. More information can be found here <a href="http://www.opensymphony.com/oscache/wiki/JSP%20Tags.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.opensymphony.com');" target="_blank">http://www.opensymphony.com/oscache/wiki/JSP%20Tags.html</a></p>
<p>A cache with an invalidation timeout as seen in the above example is great for many situations, but sometimes you need full control on when a cache entry needs invalidating. OSCache offers an API to manage the cache in your Java code. This is an example of how to invalidate it in a Java web application:</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">ServletContext context = httpServletRequest.<span class="me1">getSession</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">getServletContext</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
ServletCacheAdministrator admin = ServletCacheAdministrator.<span class="me1">getInstance</span><span class="br0">&#40;</span>context<span class="br0">&#41;</span>;<br />
Cache cache = admin.<span class="me1">getAppScopeCache</span><span class="br0">&#40;</span>context<span class="br0">&#41;</span>;<br />
cache.<span class="me1">flushEntry</span><span class="br0">&#40;</span>key<span class="br0">&#41;</span></div>
</div>
<p>Piece of cake!</p>
<p>Take care,</p>
<p>Alex</p>
<p>PS: OSCache is under the OpenSymphony Software License, Version 1.1 which is derived and fully compatible with the Apache Software License.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.core-dump.net/programming/powerful-yet-easy-caching-with-oscache/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Tackling Bottlenecks</title>
		<link>http://www.core-dump.net/productivity/tackling-bottlenecks/</link>
		<comments>http://www.core-dump.net/productivity/tackling-bottlenecks/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 10:57:49 +0000</pubDate>
		<dc:creator>alex</dc:creator>
		
		<category><![CDATA[productivity]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[optimization]]></category>

		<category><![CDATA[performance]]></category>

		<category><![CDATA[tuning]]></category>

		<guid isPermaLink="false">http://www.core-dump.net/?p=72</guid>
		<description><![CDATA[The performance of a dynamic web application can be quite unpredictable when you don’t know how many People are going to use it and of course how they are going to use it. You can predict some of the users’ behaviours and do your best to prepare your application to cope with the expected load. [...]]]></description>
			<content:encoded><![CDATA[<p>The performance of a dynamic web application can be quite unpredictable when you don’t know how many People are going to use it and of course how they are going to use it. You can predict some of the users’ behaviours and do your best to prepare your application to cope with the expected load. But sometime after the launch you suddenly find yourself in a situation where the performance of your application – or at least parts of it - is poor and the customer is unhappy. In cases like this typical reasons why you didn’t find the bottlenecks while developing are:</p>
<ul>
<li>more users than expected</li>
<li>unpredicted behaviour of users</li>
<li>the amount of data stored in the production database compared to the development database</li>
<li>missing indexes on database tables</li>
<li>slow queries that need optimizing besides adding indexes</li>
<li>inefficient code</li>
<li>insufficient resources on the servers</li>
</ul>
<p>So before using the brute force approach by throwing more hardware at the problem, the most important task to accomplish first is to find the real bottleneck. Just like in war times good intelligence is your key to winning the battle. So gather information first.</p>
<ul>
<li>Find out which parts are slow and under which circumstances the performance is poor. Talking to actual users of the app is a good approach to do so.</li>
<li>Monitor the servers using tools like <a href="http://munin.projects.linpro.no/" onclick="javascript:pageTracker._trackPageview('/outbound/article/munin.projects.linpro.no');" target="_blank">munin</a>. CPU and Memory usage can show you which part of the architecture is stressed. In some cases the webserver idles most of the time, while the database machine is under heavy load</li>
<li>Check the Database for slow queries – most databases provide tools and statistics to determine the slowest queries. This will help you find out where indexes might be missing or which queries need optimizing</li>
<li>When optimizing queries first look at the explain plan. It can point you to the problem directly.</li>
<li> Check the DB for the most frequently executed queries – if a query is executed very often this might be a place where the application code needs optimizing or where caching might help. Add caching wherever the same piece of infrequently changing data is shown to many users many times. A great roundup on open source Java cache implementations can be found <a href="http://java-source.net/open-source/cache-solutions" onclick="javascript:pageTracker._trackPageview('/outbound/article/java-source.net');" target="_blank">here</a>.</li>
<li>Use a profiler to find out where in your code the application gets stuck. Chances are high that you end up locating the place where one of the slow queries is executed</li>
</ul>
<p>Then start optimizing the parts you expect the most performance boost from. Be careful though when adding indexes on database tables with huge amounts of data – check if there is sufficient disk/table space available on the RDBMS. Indexes can also have effects on the performance of write operations.</p>
<p>If all this brain doesn’t solve the problem you might need to add muscle to your hardware:</p>
<ul>
<li>Scale vertically by adding RAM and increasing CPU</li>
<li>Scale horizontally by adding machines, which is a lot easier for web servers as it is for database servers</li>
<li>An excellent piece of literature on this topic is “<a href="http://www.amazon.com/Scalable-Internet-Architectures-Developers-Library/dp/067232699X" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.amazon.com');" target="_blank">Scalable Internet Architectures</a>” by Theo Schlossnagle</li>
</ul>
<p>Take care&#8230;</p>
<p>Alex</p>
]]></content:encoded>
			<wfw:commentRss>http://www.core-dump.net/productivity/tackling-bottlenecks/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The art of writing a good proposal</title>
		<link>http://www.core-dump.net/management/the-art-of-writing-a-good-proposal/</link>
		<comments>http://www.core-dump.net/management/the-art-of-writing-a-good-proposal/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 11:24:06 +0000</pubDate>
		<dc:creator>alex</dc:creator>
		
		<category><![CDATA[management]]></category>

		<category><![CDATA[organization]]></category>

		<category><![CDATA[pricing]]></category>

		<category><![CDATA[proposal]]></category>

		<guid isPermaLink="false">http://www.core-dump.net/?p=68</guid>
		<description><![CDATA[Let’s face it: we hate writing proposals. We’re engineers and we want to do what we do best: write code, design great architectures, try out new technologies, stuff like that. Nevertheless proposals are extremely important: no proposal -&#62; no project -&#62; no work -&#62; no pay -&#62; no doughnuts.
So here are my rules for writing [...]]]></description>
			<content:encoded><![CDATA[<p>Let’s face it: we hate writing proposals. We’re engineers and we want to do what we do best: write code, design great architectures, try out new technologies, stuff like that. Nevertheless proposals are extremely important: no proposal -&gt; no project -&gt; no work -&gt; no pay -&gt; no doughnuts.</p>
<p>So here are my rules for writing a good proposal:</p>
<p><strong>1) Embrace Proposals</strong><br />
Especially in times like these, where every customer seems to be cutting back costs, we should be happy about any request for a proposal that comes in. And with this positive attitude our proposals will get a lot better. The customer is our friend. We need her more desperately than the she needs us.</p>
<p><strong>2) Think win-win.</strong><br />
Don’t be too cheap, don’t be too expensive. Just be fair. Customers are smart – they know if they can trust us or not. Both being too cheap and being too expensive may seem like loose-win or win-loose at first sight, but will lead to a loose-loose situation in the long run. If you’re too cheap, the customers get used to your prices and you won’t enjoy working for them anymore. Being too expensive will lead to unhappy customers, because they won’t trust you and find someone else for the job. We are exchangeable.</p>
<p><strong>3) Don’t just think in terms of man-days.</strong><br />
Simply thinking in terms of man-days is not too bad. If estimated properly the project will cover your costs and maybe leave you some profit on top. But imagine you can finish a complex project in a short amount of time, because you already have this great component you’ve written in a previous project that you can use for this one, too? Ask yourself: how much is it worth? How much would others charge for the same project?</p>
<p><strong>4) Cover your back</strong><br />
Always have someone else check your proposal. Never send a proposal to a customer, no one else has taken a good look at. Ask someone to check the proposal critically, question everything from the concept down to the pricing. The resulting proposal will contain less typos and someone else might find something significant you might have forgotten or overlooked. Maybe someone else will think it’s too cheap, too expensive, lacking detail or whatever.</p>
<p><strong>5) Be complete and be clear</strong><br />
The clearer and the more complete the definition of the deliverables, the less potential for discussions with the customer there’ll be. Not only mention what you will deliver, also mention what you will not deliver. If the proposal is about writing a custom intranet application, be sure to mention that setting up the production and staging environment is not part of the proposal – if, of course, someone else is in charge of that. Sometimes, out of laziness, we write stuff like “standard reporting – 1000$”. The customer will probably have a completely different opinion on what a standard report is than you. Sentences like this have the potential of eating up your profit, because the customer expects you to make him happy. And instead of a CSV export of customer addresses, you find yourself writing a full featured CRM application.</p>
<p><strong>7) Find the pitfalls</strong><br />
Every project contains risks. Think about worst case scenarios and everything that could go wrong during the project – e.g. introducing a new technology you haven’t worked with before. The more risks you find, the more buffer you add to the price. Sometimes it even makes sense to mention the risks and the customer will better understand the pricing.</p>
<p><strong>7) Blurry details, blurry price</strong><br />
If it’s not completely clear what the customer wants and what the desired outcome of the project will be, you’re walking on thin ice with a proposal. In that case it’s often better to name ballpark numbers and ranges instead of a fixed price.</p>
<p>Is there anything I’ve forgotten? Let me know and leave a comment – I’ll appreciate it.</p>
<p>Alex</p>
]]></content:encoded>
			<wfw:commentRss>http://www.core-dump.net/management/the-art-of-writing-a-good-proposal/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The Beauty of Enums</title>
		<link>http://www.core-dump.net/programming/the-beauty-of-enums/</link>
		<comments>http://www.core-dump.net/programming/the-beauty-of-enums/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 10:51:10 +0000</pubDate>
		<dc:creator>alex</dc:creator>
		
		<category><![CDATA[programming]]></category>

		<category><![CDATA[clean code]]></category>

		<category><![CDATA[style]]></category>

		<guid isPermaLink="false">http://www.core-dump.net/?p=55</guid>
		<description><![CDATA[One part of reviewing and refactoring code is finding and removing code smells. An example, which I encounter quite often is the outmoded manner of coding Enumeration-like behaviour using int-constants. Or worse: String constants. The java.util.Calendar-class serves as a great example for this former best practice, before the Enumeration-Type was introduced with Java release 1.5.
Imagine [...]]]></description>
			<content:encoded><![CDATA[<p>One part of reviewing and refactoring code is finding and removing code smells. An example, which I encounter quite often is the outmoded manner of coding Enumeration-like behaviour using int-constants. Or worse: String constants. The java.util.Calendar-class serves as a great example for this former best practice, before the Enumeration-Type was introduced with Java release 1.5.</p>
<p>Imagine you want to get a java.util.Date object pointing to the 1st of January 2009, midnight. This is one way of doing it:</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ACalendar+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.com');"><span class="kw3">Calendar</span></a> cal = <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ACalendar+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.com');"><span class="kw3">Calendar</span></a>.<span class="me1">getInstance</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
cal.<span class="me1">set</span><span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ACalendar+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.com');"><span class="kw3">Calendar</span></a>.<span class="me1">YEAR</span>, <span class="nu0">2009</span><span class="br0">&#41;</span>;<br />
cal.<span class="me1">set</span><span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ACalendar+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.com');"><span class="kw3">Calendar</span></a>.<span class="me1">MONTH</span>, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ACalendar+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.com');"><span class="kw3">Calendar</span></a>.<span class="me1">JANUARY</span><span class="br0">&#41;</span>;<br />
cal.<span class="me1">set</span><span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ACalendar+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.com');"><span class="kw3">Calendar</span></a>.<span class="me1">DAY_OF_MONTH</span>, <span class="nu0">1</span><span class="br0">&#41;</span>;<br />
cal.<span class="me1">set</span><span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ACalendar+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.com');"><span class="kw3">Calendar</span></a>.<span class="me1">HOUR_OF_DAY</span>, <span class="nu0">0</span><span class="br0">&#41;</span>;<br />
cal.<span class="me1">set</span><span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ACalendar+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.com');"><span class="kw3">Calendar</span></a>.<span class="me1">MINUTE</span>, <span class="nu0">0</span><span class="br0">&#41;</span>;<br />
cal.<span class="me1">set</span><span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ACalendar+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.com');"><span class="kw3">Calendar</span></a>.<span class="me1">SECOND</span>, <span class="nu0">0</span><span class="br0">&#41;</span>;<br />
cal.<span class="me1">set</span><span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ACalendar+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.com');"><span class="kw3">Calendar</span></a>.<span class="me1">MILLISECOND</span>, <span class="nu0">0</span><span class="br0">&#41;</span>;<br />
<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ADate+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.com');"><span class="kw3">Date</span></a> myDate = cal.<span class="me1">getTime</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</div>
<p>This has been a clean way of implementing and “imitating” enum-like behaviour in pre 1.5 times and of course in projects that require a lower java version.</p>
<p>Since we’re passing ints to the set method, it is possible to do something like this, without having the compiler complain about it (seen it done before):</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">cal.<span class="me1">set</span><span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ACalendar+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.com');"><span class="kw3">Calendar</span></a>.<span class="me1">MONTH</span>, <span class="nu0">1</span><span class="br0">&#41;</span>;</div>
</div>
<p>And due to the fact that the number of the months in the Calendar class starts with 0 this would create a Date object pointing to the 1st of February. Ouch.  An even more evil way of misusing the Calendar class could be this:</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">cal.<span class="me1">set</span><span class="br0">&#40;</span><span class="nu0">2</span>, <span class="nu0">1</span><span class="br0">&#41;</span>;</div>
</div>
<p>I’ve never seen this done before, but looking at it, I must say it really hurts.</p>
<p>Since the release of Java 1.5 there is a much better way of programming that kind of behaviour using the Enumeration type. This is how a simple Month enumeration could look like:</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="kw2">public</span> <span class="kw2">enum</span> SimpleMonthEnum <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; JANUARY, FEBURARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER,OCTOBER, NOVEMBER, DECEMBER;<br />
<span class="br0">&#125;</span></div>
</div>
<p>But we can add a little more brain to the implementation:</p>
<p>We’ll add member variables for the name, index and number of days, a constructor with arguments for each of these values and we’ll provide getters for retrieving them. Additionally we’ll add a method for calculating the correct number of days depending on a given year, considering leap years.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="kw2">package</span> com.<span class="me1">coredump</span>.<span class="me1">enumTest</span>;</p>
<p><span class="kw2">public</span> <span class="kw2">enum</span> MonthEnum <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// define the items of the enumeration</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; JANUARY<span class="br0">&#40;</span><span class="st0">&quot;January&quot;</span>, <span class="nu0">1</span>, <span class="nu0">31</span><span class="br0">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; FEBRUARY<span class="br0">&#40;</span><span class="st0">&quot;February&quot;</span>, <span class="nu0">2</span>, <span class="nu0">28</span><span class="br0">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; MARCH<span class="br0">&#40;</span><span class="st0">&quot;March&quot;</span>, <span class="nu0">3</span>, <span class="nu0">31</span><span class="br0">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span>&#8230;<span class="br0">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; NOVEMBER<span class="br0">&#40;</span><span class="st0">&quot;November&quot;</span>, <span class="nu0">11</span>, <span class="nu0">30</span><span class="br0">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; DECEMBER<span class="br0">&#40;</span><span class="st0">&quot;December&quot;</span>, <span class="nu0">12</span>, <span class="nu0">31</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// member variables</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.com');"><span class="kw3">String</span></a> name;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">private</span> <span class="kw4">int</span> index;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">private</span> <span class="kw4">int</span> numberOfDays;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// constructor</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">private</span> MonthEnum<span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.com');"><span class="kw3">String</span></a> name, <span class="kw4">int</span> index, <span class="kw4">int</span> numberOfDays<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">this</span>.<span class="me1">name</span> = name;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">this</span>.<span class="me1">index</span> = index;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">this</span>.<span class="me1">numberOfDays</span> = numberOfDays;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.com');"><span class="kw3">String</span></a> getName<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> name;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">int</span> getNumber<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> index;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">int</span> getNumberOfDays<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> numberOfDays;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">int</span> calcNumberOfDays<span class="br0">&#40;</span><span class="kw4">int</span> year<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// check for leap years:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// year modulo 4 is 0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// if year modulo 100 equals 0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// and year modulo 400 is not 0, it&#8217;s not a leap year</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw2">this</span>.<span class="me1">equals</span><span class="br0">&#40;</span>MonthEnum.<span class="me1">FEBRUARY</span><span class="br0">&#41;</span> &amp;&amp; year%<span class="nu0">4</span> == <span class="nu0">0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &amp;&amp; !<span class="br0">&#40;</span>year%<span class="nu0">100</span> == <span class="nu0">0</span> &amp;&amp; year%<span class="nu0">400</span> != <span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> <span class="kw2">this</span>.<span class="me1">numberOfDays</span> <span class="nu0">+1</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> <span class="kw2">this</span>.<span class="me1">numberOfDays</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>And here’s an example of how the enumeration can be used:</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="kw2">public</span> <span class="kw2">class</span> MontEnumClient <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">private</span> <span class="kw2">static</span> <span class="kw4">void</span> printMonthDetails<span class="br0">&#40;</span>MonthEnum monthEnum<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ASystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.com');"><span class="kw3">System</span></a>.<span class="me1">out</span>.<span class="me1">println</span><span class="br0">&#40;</span>monthEnum.<span class="me1">getName</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ASystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.com');"><span class="kw3">System</span></a>.<span class="me1">out</span>.<span class="me1">println</span><span class="br0">&#40;</span>monthEnum.<span class="me1">getNumber</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ASystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.com');"><span class="kw3">System</span></a>.<span class="me1">out</span>.<span class="me1">println</span><span class="br0">&#40;</span>monthEnum.<span class="me1">getNumberOfDays</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">static</span> <span class="kw4">void</span> main<span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.com');"><span class="kw3">String</span></a><span class="br0">&#91;</span><span class="br0">&#93;</span> args<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ASystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.com');"><span class="kw3">System</span></a>.<span class="me1">out</span>.<span class="me1">println</span><span class="br0">&#40;</span>MonthEnum.<span class="me1">FEBRUARY</span>.<span class="me1">calcNumberOfDays</span><span class="br0">&#40;</span><span class="nu0">2008</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ASystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.com');"><span class="kw3">System</span></a>.<span class="me1">out</span>.<span class="me1">println</span><span class="br0">&#40;</span>MonthEnum.<span class="me1">FEBRUARY</span>.<span class="me1">calcNumberOfDays</span><span class="br0">&#40;</span><span class="nu0">2009</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ASystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.com');"><span class="kw3">System</span></a>.<span class="me1">out</span>.<span class="me1">println</span><span class="br0">&#40;</span>MonthEnum.<span class="me1">FEBRUARY</span>.<span class="me1">calcNumberOfDays</span><span class="br0">&#40;</span><span class="nu0">1700</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ASystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.com');"><span class="kw3">System</span></a>.<span class="me1">out</span>.<span class="me1">println</span><span class="br0">&#40;</span>MonthEnum.<span class="me1">FEBRUARY</span>.<span class="me1">calcNumberOfDays</span><span class="br0">&#40;</span><span class="nu0">1600</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; printMonthDetails<span class="br0">&#40;</span>MonthEnum.<span class="me1">DECEMBER</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>I warmly recommend the use of this great feature of the Java language. It definitely adds more type safety, ease of use and security to your application. But unfortunately it seems to me, that it still hasn’t reached the popularity that it really deserves, yet.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.core-dump.net/programming/the-beauty-of-enums/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Better code</title>
		<link>http://www.core-dump.net/programming/better-code/</link>
		<comments>http://www.core-dump.net/programming/better-code/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 12:48:54 +0000</pubDate>
		<dc:creator>alex</dc:creator>
		
		<category><![CDATA[programming]]></category>

		<category><![CDATA[clean code]]></category>

		<category><![CDATA[code review]]></category>

		<category><![CDATA[optimization]]></category>

		<category><![CDATA[refactoring]]></category>

		<guid isPermaLink="false">http://www.core-dump.net/?p=39</guid>
		<description><![CDATA[Whether you’re part of an agile team using methods like XP or Scrum, or processing your projects in a more classic way with RUP or even waterfall, in most cases you’re part of a team of developers. Chances that someday you’ll have to work with or (worse) debug code someone else has written are 100%. [...]]]></description>
			<content:encoded><![CDATA[<p>Whether you’re part of an agile team using methods like XP or Scrum, or processing your projects in a more classic way with RUP or even waterfall, in most cases you’re part of a team of developers. Chances that someday you’ll have to work with or (worse) debug code someone else has written are 100%. And who of us hasn’t complained about having to deal with “the mess” someone else has made. And probably some of our co-workers have been scratching their heads with both hands looking at some piece of code we’ve written after midnight with a numb mind in shipping hell. Nobody’s perfect.</p>
<p>So what can we do about this situation? Whining, complaining and pointing fingers won’t make the code any better.</p>
<p>Just recently I read “<a href="http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882/ref=pd_bbs_sr_1?ie=UTF8&amp;s=books&amp;qid=1235330225&amp;sr=8-1" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.amazon.com');" target="_blank">Clean Code</a>” by Robert C. Martin. Zillions of blog entries were recommending this book, so I had to get it myself. I was probably one the last people on earth who hadn’t read it. It’s a great piece of programming literature. Reading it I found myself nodding my head a lot, agreeing with many of the points made and regretted I hadn’t read it earlier. There are some aspects I do not agree with 100% but they were very few.</p>
<p>One thing that impressed me a lot because of its simpleness is the “boy scout rule”: “Leave the campground cleaner than you found it”. When working with a piece of code, make your changes and commit it a little cleaner to your version control system. Let me give you an example.</p>
<p>I was debugging a class for creating financial charts. The following piece of code was scattered in it with slight variations about 20 times.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">domainAxis.<span class="me1">setTickLabelFont</span><span class="br0">&#40;</span><span class="kw2">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AFont+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.com');"><span class="kw3">Font</span></a><span class="br0">&#40;</span><span class="st0">&quot;Arial Narrow&quot;</span>,<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AFont+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.com');"><span class="kw3">Font</span></a>.<span class="me1">BOLD</span>,<span class="nu0">11</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</div>
<p>The reason I was debugging the class was that the font sizes within the charts did not look right when run on the production environment. Simple change made: remove the hard coded String and the numeric font size, and replace them with constants.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">domainAxis.<span class="me1">setTickLabelFont</span><span class="br0">&#40;</span><span class="kw2">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AFont+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.com');"><span class="kw3">Font</span></a><span class="br0">&#40;</span>CHARTFONT,<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AFont+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.com');"><span class="kw3">Font</span></a>.<span class="me1">BOLD</span>,FONT_SIZE_NORMAL<span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</div>
<p>No big deal, but improving the readability and maintainability of the code a little bit. Imagine a whole team following this simple principle. More productivity, less rotten code, better team spirit. And the best thing about it: it’s absolutely free!</p>
<p>Happy coding!<br />
Alex</p>
]]></content:encoded>
			<wfw:commentRss>http://www.core-dump.net/programming/better-code/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Getting things started&#8230; and done</title>
		<link>http://www.core-dump.net/productivity/getting-things-started-and-done/</link>
		<comments>http://www.core-dump.net/productivity/getting-things-started-and-done/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 14:30:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[productivity]]></category>

		<category><![CDATA[GTD]]></category>

		<category><![CDATA[organization]]></category>

		<category><![CDATA[self-management]]></category>

		<category><![CDATA[time-management]]></category>

		<guid isPermaLink="false">http://www.core-dump.net/?p=1</guid>
		<description><![CDATA[I spend about one hour a day commuting between my office and my home by car. During drive-time I used to listen to the radio a lot. Someday the flooding of air time with commercials drove me nuts, so I decided to change something about that. After having spent some time with podcasts I found [...]]]></description>
			<content:encoded><![CDATA[<p>I spend about one hour a day commuting between my office and my home by car. During drive-time I used to listen to the radio a lot. Someday the flooding of air time with commercials drove me nuts, so I decided to change something about that. After having spent some time with podcasts I found out that audiobooks are the better alternative for me: they are professionally produced,  you can read the reviews on them on amazon before you buy them and they usually - when selected wisely - contain less crap than some podcasts (I am a podcaster myself (<a href="http://www.de-lite.de" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.de-lite.de');" target="_self">www.de-lite.de</a>), and I&#8217;m sure many people consider my productions crap, too). The downside is - audiobooks are not free <img src='http://www.core-dump.net/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> </p>
<p>Anyway - just recently I downloaded and listened to &#8220;<strong><a href="http://www.audible.com/adbl/site/products/ProductDetail.jsp?productID=BK_SANS_001043&amp;BV_UseBVCookie=Yes" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.audible.com');" target="_blank"><strong>Getting Things Done: The Art of Stress-Free Productivity </strong></a></strong>&#8221; by David Allen, a book everybody I know obviously had already read, except for me. When I first heard of GTD a couple of years ago, what first came to my mind was some kind of car, a Gran Turismo with a Diesel engine or something like that. Then I learned it was a methodology for self management. Some people I know claim to be using GTD as a method for self-management. Now, looking at some of their desktops (both digital and analog) I know they aren&#8217;t.</p>
<p>Many poeple misunderstand GTD simply as using a specific digital tool to store and manage all their todos. In fact it is more of a methodology or even a philosophy on how to organize both your professional and private life. And the toolset for GTD can vary from person to person. In order to be doing GTD of course you need tools, but those can be completely analogue. A printed calendar, a stack of paper, a pen and a bunch of file folders will suffice for some people if used properly.</p>
<p>So what is this GTD thing all about? I&#8217;ll try to outline the basic steps of the methodology in my own humble words (and probably missing a lot of points - sorry in advance!):</p>
<p><strong>1) Collect</strong></p>
<ul>
<li>collect your thoughts, what&#8217;s bothering you at the moment, get it all out of your brain and transfer it to a physical system (e.g. a sheet of paper). When doing this for the first time, it will probably take you hours to finish that process. The good news is that once you&#8217;ve got all of your projects and tasks together, adding the additional stuff that pops up each day won&#8217;t cost you a lot of time</li>
<li>stuff like email does not need to be collected. It&#8217;s already stored in your inbox. It just has to be processed - and that&#8217;s easier than you might think. Before I started following the rules hundreds of emails were lurking around in my inbox.</li>
<li>the aim is to free your &#8220;psychic RAM&#8221; from all that&#8217;s in there. This will in turn free a lot of energy and take away stress from you. &#8220;It&#8217;s a lot easier to relax when you know what you&#8217;re NOT doing at the moment&#8221; is a proverb David Allen uses a lot. And as I experienced this is so true.</li>
</ul>
<p><strong>2) Process</strong></p>
<ul>
<li> look at everything that you&#8217;ve collected and decide what you have to do about it</li>
<li>some of the items are actionable and won&#8217;t take longer than two minutes, e.g. &#8220;answering that email&#8221; or suchlike. Do those immediately and get rid of them</li>
<li> in case the item is not actionable, consider if it might be actionable someday maybe -&gt; put those on a separate list</li>
<li>in case the item is not actionable, consider if it might be worth keeping -&gt; throw it away if not, otherwise file it</li>
</ul>
<p><strong>3) Organize</strong></p>
<ul>
<li> assign the actionable items to projects, groupe them by context (Telephone, Office, Home, En route), project, time and energy needed</li>
<li>if an action needs to be processed on a specific point of time or day in the future, add a reminder to your calendar</li>
<li> by the way: projects are things where more than one action is needed to accomplish them.</li>
</ul>
<p><strong>4) Review</strong></p>
<ul>
<li> Review your lists every day</li>
<li> look into your calendar first thing in the morning, so that you know what definitely has to done that day</li>
<li> Every week reserve about two hours time for reviewing and rethinking your projects, lists, tasks and thoughts from different angles (also the big picture)</li>
</ul>
<p><strong>5) Do</strong></p>
<p>from the list of actions chose the best one to be done next. This can vary depending on:</p>
<ul>
<li> the context: are you online? have you got access to a phone? are you in your car for making errands? etc.</li>
<li> time available: if you&#8217;ve got a ten minutes time slot before a meeting, choose a task you can finish within that amount of time</li>
<li> energy: if you&#8217;re tired, choose a no-brainer, otherwise something more sophisticated.</li>
</ul>
<p>The audiobook cost me 30 bucks and it was one of my best investments ever. I&#8217;ve been following the rules for a week now and my impression is, it seems to be working fine for me. For the first time in years the number of emails in my inbox is 0, NULL, zip, nada. Pure joy! It even made me start this blog - something I&#8217;ve been thinking about for months but never got started with.</p>
<p>In one of my next posts I&#8217;ll write about my GTD toolset and how I work with it every day.</p>
<p>Take care,<br />
Alex</p>
<p><a href="http://www.davidco.com" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.davidco.com');" target="_blank">David Allens website</a><br />
<a href="http://www.amazon.com/Getting-Things-Done-Stress-Free-Productivity/dp/0142000280/ref=pd_bbs_sr_1?ie=UTF8&amp;s=books&amp;qid=1234978517&amp;sr=8-1" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.amazon.com');" target="_blank"> The book on amazon</a><br />
<a href="http://www.audible.com/adbl/site/products/ProductDetail.jsp?productID=BK_SANS_001043&amp;BV_UseBVCookie=Yes" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.audible.com');" target="_blank"> The audiobook</a><br />
<a href="http://en.wikipedia.org/wiki/Getting_Things_Done" onclick="javascript:pageTracker._trackPageview('/outbound/article/en.wikipedia.org');" target="_blank"> about GTD on wikipedia</a></p>
<p>PS: feel free to leave a comment, if you liked this post. If not, please leave a comment, too and let me know where I can improve. I appreciate it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.core-dump.net/productivity/getting-things-started-and-done/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Easy Mockery</title>
		<link>http://www.core-dump.net/programming/easy-mockery/</link>
		<comments>http://www.core-dump.net/programming/easy-mockery/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 05:55:22 +0000</pubDate>
		<dc:creator>alex</dc:creator>
		
		<category><![CDATA[programming]]></category>

		<category><![CDATA[clean code]]></category>

		<category><![CDATA[mock objects]]></category>

		<category><![CDATA[tdd]]></category>

		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.core-dump.net/?p=17</guid>
		<description><![CDATA[ 
Anyone who ever seriously started writing unit tests will sooner or later have come to the conclusion, that it helps isolating small testable chunks of code resulting in a clean structure of methods within a class and forcing the developer to write cleaner code. This is easy as long as the tested code does [...]]]></description>
			<content:encoded><![CDATA[<p><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:HyphenationZone>21</w:HyphenationZone> <w:PunctuationKerning /> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><!--  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-update:auto; 	mso-style-parent:""; 	margin:0cm; 	margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	font-family:Arial; 	mso-fareast-font-family:"Times New Roman"; 	mso-bidi-font-family:"Times New Roman";} pre 	{margin:0cm; 	margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	font-family:"Courier New"; 	mso-fareast-font-family:"Times New Roman";} @page Section1 	{size:595.3pt 841.9pt; 	margin:70.9pt 1.0cm 70.9pt 1.0cm; 	mso-header-margin:35.45pt; 	mso-footer-margin:35.45pt; 	mso-paper-source:15 0;} div.Section1 	{page:Section1;} --><!--[if gte mso 10]> <mce:style><!   /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Normale Tabelle"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-parent:""; 	mso-padding-alt:0cm 5.4pt 0cm 5.4pt; 	mso-para-margin:0cm; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	font-family:"Times New Roman"; 	mso-ansi-language:#0400; 	mso-fareast-language:#0400; 	mso-bidi-language:#0400;} --> <!--[endif]--></p>
<p class="MsoNormal"><span lang="EN-GB">Anyone who ever seriously started writing unit tests will sooner or later have come to the conclusion, that it helps isolating small testable chunks of code resulting in a clean structure of methods within a class and forcing the developer to write cleaner code. This is easy as long as the tested code does not work with data or configurations that might change depending on the environment in which the test are run.</span></p>
<p class="MsoNormal"><span lang="EN-GB">My two favourite basic rules for writing tests (Thanks <a href="http://blog.objectmentor.com/" onclick="javascript:pageTracker._trackPageview('/outbound/article/blog.objectmentor.com');" target="_blank">uncle bob</a>!) are<br />
</span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<ul>
<li><span lang="EN-GB">tests must run anywhere. (e.g. on a continuous integration server)</span></li>
<li><span lang="EN-GB">tests must run fast, so they’re fun running them.</span></li>
</ul>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB">As soon as your tests depend on a database containing specific data or a file system with a certain directory structure you’re in trouble. In my experience many programmers write test for methods that are easy to write tests for, and avoid the more complicated cases requiring setting up test data and such like.</span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB">A really cool way for decoupling tests from dependencies like this, speeding up their execution time and finally leading to a much better code coverage are mock objects. </span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB">A mock library I really enjoy using is easymock. Let me show you an example of how easy easymock (<a href="http://www.easymock.org" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.easymock.org');" target="_blank">http://www.easymock.org</a>) really is.</span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB">First include this library to your classpath:<strong> easymock.jar</strong></span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB">In case you want to mock classes that do not implement an interface, additionally add this library: <strong>easymockclassextension.jar</strong></span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB">Now you can start writing your isolated test making use of mock objects</span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB">Add this include to your test class:</span></p>
<p class="MsoNormal">
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="co2">import static org.easymock.classextension.EasyMock.*;</span></div>
</div>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB">or this if you’re mocking interfaces:</span></p>
<p class="MsoNormal"><span lang="EN-GB"></p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="co2">import static org.easymock.EasyMock.*;</span></div>
</div>
<p></span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB">This is how a test could look like (example code)</span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal">
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">@Test<br />
<span class="kw2">public</span> testMyServiceMethod<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p><span class="coMULTI">/* create a mock object of the class that has dependencies on the environment in which it’s used */</span><br />
ClassToMock mock = createMock<span class="br0">&#40;</span>ClassToMock.<span class="kw2">class</span><span class="br0">&#41;</span>;</p>
<p><span class="coMULTI">/* In this example we’re going to call a method of the mocked class that returns an Object of the type ResultObject. Create a dummy object, that the method call should return later */</span><br />
ResultObject resultObject = <span class="kw2">new</span> ResultObject<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
resultObject.<span class="me1">setXyzProperty</span><span class="br0">&#40;</span>“test”<span class="br0">&#41;</span>;</p>
<p><span class="coMULTI">/* let the mock object know which method is going to be called later with which parameters. Also define the result of the method call. */</span><br />
expect<span class="br0">&#40;</span>mock.<span class="me1">methodToMock</span><span class="br0">&#40;</span>testParam<span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">andReturn</span><span class="br0">&#40;</span>resultObject<span class="br0">&#41;</span>;</p>
<p><span class="coMULTI">/* the class you’re testing and that’s going to make use of the mock object, ideally holds it in an instance variable, accessible by means of a setter method. It can easily be replaced with a mock. If you’re using the Spring framework for dependency injection, your classes will usually be structured this way already. */</span><br />
objectToTest.<span class="me1">setTheObject</span><span class="br0">&#40;</span>mock<span class="br0">&#41;</span>;</p>
<p><span class="coMULTI">/* GO! */</span><br />
replay<span class="br0">&#40;</span>mock<span class="br0">&#41;</span>;</p>
<p><span class="coMULTI">/* in the object to test, call the method which is going to make use of the mocked object. */</span><br />
<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.com');"><span class="kw3">String</span></a> result = objectToTest.<span class="me1">methodToTest</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</p>
<p><span class="coMULTI">/* some asserts which are the essence of our test */</span><br />
assertEquals<span class="br0">&#40;</span>“expected”, result<span class="br0">&#41;</span>;</p>
<p><span class="coMULTI">/* optionally check if the mock object was used as defined before. If the method was not called as expected, verify will fail. So in addition to the asserts this enables us to test if the expected calls to the mocked object were done */</span><br />
verify<span class="br0">&#40;</span>mock<span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></div>
</div>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB">Mock Objects will definitely help you decoupling your tests from platform dependencies. They will make your tests faster and more fun to run.</span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB">Alex</span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span lang="EN-GB"><span> </span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.core-dump.net/programming/easy-mockery/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

