<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Objectopia &#187; Chris Burnley</title>
	<atom:link href="http://objectopia.com/author/cburnley/feed/" rel="self" type="application/rss+xml" />
	<link>http://objectopia.com</link>
	<description></description>
	<lastBuildDate>Fri, 23 Dec 2011 12:33:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='objectopia.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Objectopia &#187; Chris Burnley</title>
		<link>http://objectopia.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://objectopia.com/osd.xml" title="Objectopia" />
	<atom:link rel='hub' href='http://objectopia.com/?pushpress=hub'/>
		<item>
		<title>Weld JUnit 4 Runner</title>
		<link>http://objectopia.com/2011/05/29/weld-junit-4-runner/</link>
		<comments>http://objectopia.com/2011/05/29/weld-junit-4-runner/#comments</comments>
		<pubDate>Sun, 29 May 2011 02:18:54 +0000</pubDate>
		<dc:creator>Chris Burnley</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://objectopia.com/?p=362</guid>
		<description><![CDATA[I&#8217;ve been having a look at Weld recently and wanted to be able to try some stuff out without a container in JUnit, but couldn&#8217;t find a JUnit Runner class to do it for me. I was really suprised how simple it was: Now you can do this : Because your test class is just [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=362&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been having a look at <a title="Weld" href="http://seamframework.org/Weld">Weld</a> recently and wanted to be able to try some stuff out without a container in JUnit, but couldn&#8217;t find a JUnit Runner class to do it for me.</p>
<p>I was really suprised how simple it was:</p>
<p><pre class="brush: java; light: true;">
package org.objectopia.test;

import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;

import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.InitializationError;

public class WeldJUnit4Runner extends BlockJUnit4ClassRunner {

    private final Class klass;
    private final Weld weld;
    private final WeldContainer container;

    public WeldJUnit4Runner(final Class klass) throws InitializationError {
        super(klass);
        this.klass = klass;
        this.weld = new Weld();
        this.container = weld.initialize();
    }

    @Override
    protected Object createTest() throws Exception {
        final Object test = container.instance().select(klass).get();

        return test;
    }
}
</pre></p>
<p>Now you can do this :</p>
<p><pre class="brush: java; light: true;">
@RunWith(WeldJUnit4Runner.class)
public class PersistenceTest {

    @Inject UserRepository repository;

    ...
}
</pre></p>
<p>Because your test class is just another CDI bean, you can inject any bean reference you require.</p>
<p>This is where the power of CDI comes in to play, you can do something like this:</p>
<p><pre class="brush: java; light: true;">
    @Inject @Mock UserRepository userRepository;
</pre></p>
<p>And create a producer method to mock it out:</p>
<p><pre class="brush: java; light: true;">
    @Produces @Mock UserRepository createUserRepository() { ... }
</pre></pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/objectopia.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/objectopia.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/objectopia.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/objectopia.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/objectopia.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/objectopia.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/objectopia.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/objectopia.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/objectopia.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/objectopia.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/objectopia.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/objectopia.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/objectopia.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/objectopia.wordpress.com/362/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=362&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://objectopia.com/2011/05/29/weld-junit-4-runner/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ea90ab2b972631952cf64bb4228e6f76?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">chris</media:title>
		</media:content>
	</item>
		<item>
		<title>The arrogance of Gantt charts</title>
		<link>http://objectopia.com/2009/11/17/the-arrogance-of-gantt-charts/</link>
		<comments>http://objectopia.com/2009/11/17/the-arrogance-of-gantt-charts/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 21:34:40 +0000</pubDate>
		<dc:creator>Chris Burnley</dc:creator>
				<category><![CDATA[Opinion]]></category>
		<category><![CDATA[project management]]></category>
		<category><![CDATA[scrum]]></category>

		<guid isPermaLink="false">http://objectopia.wordpress.com/2009/11/17/the-arrogance-of-gantt-charts/</guid>
		<description><![CDATA[Gantt charts, popularized by Microsoft Project, are a mechanism for managing projects. The idea is that you list all the tasks required to complete a project. You then estimate how long each task will take. Once you figure out the dependencies between the tasks you the layout a plan from left to right connecting up [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=295&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Gantt charts, popularized by Microsoft Project, are a mechanism for managing projects. The idea is that you list all the tasks required to complete a project. You then estimate how long each task will take. Once you figure out the dependencies between the tasks you the layout a plan from left to right connecting up all the dependent tasks. This allows for some parallelism between non dependent tasks. Given the project start date and all the durations you get the project end date.</p>
<p>As long as everyone sticks to the plan, then the project will be completed on time.</p>
<p>Simple, eh? Err &#8211; not so fast! The major flaw is that Gantt charts are task focused so when a new task is discovered the project is guaranteed to be late. The reason behind this is that developers are focused on delivery of the tasks they are assigned &#8211; not value to the client. Coupled with the truism that tasks will take as much time as they are given and you <em>will</em> be late.</p>
<p>The task-centric approach only hints at the real problem with  Gantt charts: that better planning and task discovery up front would have resolved these issues. This is the most deplorable aspect: God-like wisdom <em>can</em> be achieved and would have fixed the problem.</p>
<p>Historically, software development has used the notion of &#8220;defined process control&#8221; where all aspects of the plan can be controlled, to a low-level and to a high-degree of accuracy. This does not work for most software projects because software development is not a simple undertaking- it is usually a complex process where small changes in the inputs can greatly affect the outcome.</p>
<p>Big, upfront planning that depends on infinite wisdom does not work and the only mechanism we have for complex problems is Empirical Process Control. This is the notion of frequent inspection and adaptation to a process. </p>
<p>Emperical control is _the_ key to Agile software. You&#8217;re not are Agile if you don&#8217;t have a regular process for improvement &#8211; you&#8217;re just hacking away.</p>
<p>Gantt charts have no place in an agile process; they are the tool of bluff used by the project manager that really doesn&#8217;t understand software development.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/objectopia.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/objectopia.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/objectopia.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/objectopia.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/objectopia.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/objectopia.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/objectopia.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/objectopia.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/objectopia.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/objectopia.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/objectopia.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/objectopia.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/objectopia.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/objectopia.wordpress.com/295/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=295&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://objectopia.com/2009/11/17/the-arrogance-of-gantt-charts/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ea90ab2b972631952cf64bb4228e6f76?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">chris</media:title>
		</media:content>
	</item>
		<item>
		<title>Thought for Friday: What are we going to do about the crap code ?</title>
		<link>http://objectopia.com/2009/07/24/what-are-we-going-to-do-about-the-crap-code/</link>
		<comments>http://objectopia.com/2009/07/24/what-are-we-going-to-do-about-the-crap-code/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 01:31:05 +0000</pubDate>
		<dc:creator>Chris Burnley</dc:creator>
				<category><![CDATA[Thought For Friday]]></category>

		<guid isPermaLink="false">http://objectopia.com/?p=183</guid>
		<description><![CDATA[Yesterday, my manager asked me &#8220;What are we going to do about the crap code?&#8221; It&#8217;s a hard question to answer because before we can answer what to do about it; we must understand what crap code is and what causes it. What is crap code? This is still a hard question, but I think [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=183&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Yesterday, my manager asked me &#8220;What are we going to do about the crap code?&#8221;</p>
<p>It&#8217;s a hard question to answer because before we can answer what to do about it; we must understand what <em>crap code is</em> and what causes it.</p>
<p>What is crap code? This is still a hard question, but I think we can at least attempt to answer it by defining what it <em>isn&#8217;t</em>:</p>
<ul>
<li>Crap code isn&#8217;t maintainable</li>
<li>Crap code isn&#8217;t easily      testable</li>
<li>Crap code isn&#8217;t as efficient      as it could be</li>
<li>Crap code isn&#8217;t      understandable without lots of comments</li>
</ul>
<p>What causes crap code? In my experience it is some combination of:</p>
<ul>
<li>Ignorance</li>
<li>Fear</li>
<li>Lack of experience, pride,      oversight, accountability, time and analysis/understanding of the domain</li>
<li>Resume-building perhaps?</li>
</ul>
<p>So what is the solution? There is no silver bullet, it requires vigilance and potentially each of these causes needs to be tackled individually.</p>
<p><strong>Ignorance</strong>: One way of tackling this is encouraging learning, peer review and discussion in the organization. Time needs to be allocated to ensure that project work doesn&#8217;t stop these activities from flourishing.</p>
<p><strong>Fear:</strong> One of the major differences between a good developer and an average one is the fear factor; good developers don&#8217;t have the same fear of changing something, or fixing something since they are confident they are not going to break something without knowing about it. Because of this, fear has the effect of destroying reuse &#8211; copy and paste code thrives in this environment. Besides learning how to study code, unit testing and other forms of automated testing are good for addressing this.</p>
<p><strong>Experience</strong>: You need to install a mentoring system to ensure that the less experienced team members have someone to go to for advice. Team members need to be exposed to different types of development work. E.g. database, business-logic, front-end / web etc. They&#8217;ll never get enough experience doing the same thing day in, day out. Ensure every commit to the code base is emailed to the rest of the team, experienced developers should be reviewing the code and suggesting changes if required.</p>
<p><strong>Pride</strong>: This is a hard one, and probably comes from the side effects of the other causes. One way is to allow team members to look after a particular module, service / sub-system.</p>
<p><strong>Oversight / Accountability</strong>: Oversight is simple &#8211; review code and don&#8217;t compromise on quality &#8211; you&#8217;ll end up regretting it at some point. Generally speaking accountability decreases the more segregated the teams are.  I.e. if you have a team of testers that are separate to your developers, the less responsibility the developers will feel to getting something right &#8211; you&#8217;ll get a &#8220;throw it over the fence&#8221; mentality. Create a team with all disciplines (developers, testers, dbas, infrastructure etc.,,).</p>
<p><strong>Time</strong>: This is about planning properly and ensuring that developers are aware of all the steps to produce bit of functionality. It&#8217;s also about being realistic when it comes to providing your estimates. Make sure you include time for producing your unit and integration tests, and don&#8217;t underestimate just so you get the job. Stress to developers that the job isn&#8217;t done until it is tested and works.</p>
<p><strong>Resume-building</strong>: This is subjective but I&#8217;ve been on projects where the tech lead has read that this new piece of technology is the ducks and they wants to get in on it just so they can put it down on their resume. They manage to get all the newest and greatest stuff in there but at what price? The code under the covers becomes a maintenance nightmare because it is far to complicated for what it needs to do. Ensure that the technology you use is decided up front. Don&#8217;t deviate unless you get further sign-off from the stakeholders. Create a list of &#8220;guiding principles&#8221; (N.B. not coding standards) to decide how you&#8217;re going to go about writing the code &#8211; and enforce code reviews on these.</p>
<p><strong>Understanding the domain</strong>:  When you start a new project it is really important, that at every step in the process you constantly to try to refactor based on your current understanding of the code. Data models are really hard to change once a system goes into production, so you&#8217;ve got to make an effort to get it right. If some aspect of the design doesn&#8217;t feel right, then it probably isn&#8217;t it. <strong>Don&#8217;t be in denial</strong> &#8211; fix it.  I&#8217;ve seen so much bad code and bugs caused because the new requirements or understanding about a system are applied to a broken domain.</p>
<p>The bottom line is, does crap code really matter? Who cares if it works, right? I think it does. And crap code is directly proportional to defects in my experience.  Defects will cost you money fixing them and cleaning up the consequences of them.</p>
<p>Fixing the crap code is no doubt a hard problem. The solutions involve constant vigilance and culture change &#8211; but it is worth it in the end.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/objectopia.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/objectopia.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/objectopia.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/objectopia.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/objectopia.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/objectopia.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/objectopia.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/objectopia.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/objectopia.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/objectopia.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/objectopia.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/objectopia.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/objectopia.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/objectopia.wordpress.com/183/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=183&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://objectopia.com/2009/07/24/what-are-we-going-to-do-about-the-crap-code/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ea90ab2b972631952cf64bb4228e6f76?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">chris</media:title>
		</media:content>
	</item>
		<item>
		<title>We only hire the best</title>
		<link>http://objectopia.com/2009/07/23/we-only-hire-the-best/</link>
		<comments>http://objectopia.com/2009/07/23/we-only-hire-the-best/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 20:50:30 +0000</pubDate>
		<dc:creator>Chris Burnley</dc:creator>
				<category><![CDATA[Opinion]]></category>

		<guid isPermaLink="false">http://objectopia.com/?p=223</guid>
		<description><![CDATA[I was recently having dinner with an acquaintance who works for a massive multinational IT company. He was telling me that at a recent company conference that, despite the economy, the CEO said the company was doing well because &#8220;we only hire the best&#8221;. I almost choked on my steak, trying to contain myself. The [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=223&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was recently having dinner with an acquaintance who works for a massive multinational IT company. He was telling me that at a recent company conference that, despite the economy, the CEO said the company was doing well because &#8220;we only hire the best&#8221;. </p>
<p>I almost choked on my steak, trying to contain myself. The sad thing was that he actually believed it. How come all companies that I&#8217;ve worked at only hires the best ? Surely all of them can&#8217;t have the best ?</p>
<p>Why do companies maintain this illusion ? Is it some sort of psychological trick so you don&#8217;t quit and join a company full of bozos ? Or do people at the top truly believe it, in some sort of paradoxical delusion ?</p>
<p>I don&#8217;t know, but it&#8217;s odd isn&#8217;t it ? </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/objectopia.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/objectopia.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/objectopia.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/objectopia.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/objectopia.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/objectopia.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/objectopia.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/objectopia.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/objectopia.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/objectopia.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/objectopia.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/objectopia.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/objectopia.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/objectopia.wordpress.com/223/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=223&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://objectopia.com/2009/07/23/we-only-hire-the-best/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ea90ab2b972631952cf64bb4228e6f76?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">chris</media:title>
		</media:content>
	</item>
		<item>
		<title>Routing around damaged processes</title>
		<link>http://objectopia.com/2009/07/16/routing-around-damaged-processes/</link>
		<comments>http://objectopia.com/2009/07/16/routing-around-damaged-processes/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 07:03:29 +0000</pubDate>
		<dc:creator>Chris Burnley</dc:creator>
				<category><![CDATA[Opinion]]></category>

		<guid isPermaLink="false">http://objectopia.com/?p=203</guid>
		<description><![CDATA[It is often said that &#8220;The Internet interprets censorship as damage and routes around it&#8221;. I don&#8217;t know how true this statement is, but I have seen this affect applied to organizational processes. When you work at a sufficiently large organization, you&#8217;ll start to employ people who&#8217;s sole responsibility is creating process. The problem with [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=203&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It is often said that &#8220;The Internet interprets censorship as damage and routes around it&#8221;. I don&#8217;t know how true this statement is, but I have seen this affect applied to organizational processes.</p>
<p>When you work at a sufficiently large organization, you&#8217;ll start to employ people who&#8217;s sole responsibility is creating process. The problem with these roles is that, if no new process is created, then those people are not seen to be doing their job. </p>
<p>Once they get started, there&#8217;ll be a process for each aspect of developing software, production releases, production data changes, process for creating a process, etc. etc. ad nauseam. (I&#8217;m not saying that there is anything wrong with processes, but more that it unsustainable to continue to create them indefinitely).  </p>
<p>This usually has either two outcomes: </p>
<ol>
<li>good people who just want to do their jobs get fed up with the red tape and leave or; </li>
<li>people &#8220;<strong>route around the damage</strong>&#8220;d process.</li>
</ol>
<p>I see #2 happen all the time. The problem is unnecessary risks are taken because it has just gotten too hard to do anything.</p>
<p>How do you solve this ? Ideally, the people that author the process should also have to follow it themselves. At the very least, you should involve the people that have to follow the process in its creation.</p>
<p>The most important thing is, you have to make following the process easy and fast. If you slow people down, they will just route around the damage (you!). </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/objectopia.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/objectopia.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/objectopia.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/objectopia.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/objectopia.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/objectopia.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/objectopia.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/objectopia.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/objectopia.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/objectopia.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/objectopia.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/objectopia.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/objectopia.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/objectopia.wordpress.com/203/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=203&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://objectopia.com/2009/07/16/routing-around-damaged-processes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ea90ab2b972631952cf64bb4228e6f76?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">chris</media:title>
		</media:content>
	</item>
		<item>
		<title>Please ! Stop using floating point numbers for financial data</title>
		<link>http://objectopia.com/2009/07/03/stop-using-floating-poin/</link>
		<comments>http://objectopia.com/2009/07/03/stop-using-floating-poin/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 00:55:18 +0000</pubDate>
		<dc:creator>Chris Burnley</dc:creator>
				<category><![CDATA[Grrrr...]]></category>
		<category><![CDATA[Java etc...]]></category>

		<guid isPermaLink="false">http://objectopia.com/?p=156</guid>
		<description><![CDATA[Again and again I see developers using doubles for storing financial data (e.g. monetary figures, interest rates etc.). This always causes some sort of rounding issue down the line. try this in your IDE: If you expect the answer to be 1 or 1.0, then you&#8217;re wrong ! Question: are you writing a game ? [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=156&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Again and again I see developers using doubles for storing financial data (e.g. monetary figures, interest rates etc.). This always causes some sort of rounding issue down the line.</p>
<p>try this in your IDE:</p>
<p><pre class="brush: java;">
double total = 0;
for (int i =0; i &lt;  10; i++){
  total += 0.1;
}
System.out.println(total);
</pre><br />
If you expect the answer to be 1 or 1.0, then you&#8217;re wrong !</p>
<p>Question: are you writing a game ? Answer: no; then use an effing BigDecimal!</p>
<p>Grrr&#8230; </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/objectopia.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/objectopia.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/objectopia.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/objectopia.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/objectopia.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/objectopia.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/objectopia.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/objectopia.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/objectopia.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/objectopia.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/objectopia.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/objectopia.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/objectopia.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/objectopia.wordpress.com/156/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=156&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://objectopia.com/2009/07/03/stop-using-floating-poin/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ea90ab2b972631952cf64bb4228e6f76?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">chris</media:title>
		</media:content>
	</item>
		<item>
		<title>Non-anaemic models and service oriented architectures</title>
		<link>http://objectopia.com/2009/05/20/non-anaemic-models-and-service-oriented-architectures/</link>
		<comments>http://objectopia.com/2009/05/20/non-anaemic-models-and-service-oriented-architectures/#comments</comments>
		<pubDate>Wed, 20 May 2009 02:04:00 +0000</pubDate>
		<dc:creator>Chris Burnley</dc:creator>
				<category><![CDATA[Java etc...]]></category>

		<guid isPermaLink="false">http://objectopia.wordpress.com/2009/05/20/non-anaemic-models-and-service-oriented-architectures/</guid>
		<description><![CDATA[The term “anaemic domain model” is used to describe an entity layer that contains very little business logic. Typically in this architecture, the business logic is contained in services and/or delegates. There are several problems with this approach: Business logic quickly gets scattered and duplicated across the system It is difficult to maintain because it [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=7&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The term “anaemic domain model” is used to describe an entity layer that contains very little business logic. Typically in this architecture, the business logic is contained in services and/or delegates. There are several problems with this approach:</p>
<ul>
<li>Business logic quickly gets scattered and duplicated across the system</li>
<li>It is difficult to maintain because it is hard to determine which class needs to be changed</li>
<li>It is difficult to test because the service/delegate usually has many dependencies</li>
<li>It is not particularly object oriented (e.g. polymorphism, which can reduce a lot of complexity by reducing ‘type-logic’, is rare)</li>
</ul>
<p>The trend these days is towards Domain Driven Design (DDD), and is a strategy against anaemic domain models. In this architecture, services are used as an ‘anti-corruption-layer’ to translate requests from the external domain to the internal domain of the system. The majority of the logic is contained within the domain model (this includes persistent and non-persistent objects).</p>
<p>When developing a non-anaemic model (e.g. DDD), it is tempting to call services directly to perform logic (to perhaps an external system, or send a message), to hide complexity from the client:</p>
<p><pre class="brush: java;">
class Account {
    Balance getBalance() {
        for(Transaction t : getTransactionService().getTransactions(…)){
            //… sum them up
        }
    }

    TransactionService getTransactionService() {
        // lookup service
    }
}
</pre></p>
<p>I think this not good design for a number of reasons:</p>
<ul>
<li>The risk of <a href="http://www.joelonsoftware.com/articles/LeakyAbstractions.html" target="_blank">Leaky Abstraction (e.g. having to declare checked Exceptions to methods)<br />
</a></li>
<li>Generally speaking, the domain model doesn’t have enough information about the nature of the method call to perform well. The service would be better suited to know how the model will be used (e.g. in a loop).</li>
<li>It is harder to test the business logic because you’ve got to mock out too many dependencies.</li>
<li>I believe that entities should be deterministic, the behaviour must be determinable given the state of the system/database.</li>
<li>Potentially introduces circular dependencies between service-&gt;model-&gt;service-&gt;model etc. which causes problems for maintainability, testing and debugging.</li>
</ul>
<p>So how do we have a nice, clean, rich domain model ? One way is to pass an implementation of an interface to the domain (e.g. a delegate to a service) so the domain can perform its logic:</p>
<p><pre class="brush: java;">
class Account {
    Balance getBalance(TransactionRepository repos) {
        // … get the transactions, sum them up
    }
}
// Getting the balance on a single account
Account account =...;
account.getBalance(singleAccountTransactionRepository);
// Getting the balance on many accounts
List&lt;Account&gt; accounts = ...;
for(Account account : accounts){
          account.getBalance(allAccountTransactionRepository);
}
</pre></p>
<p>The idea here is that you substitute the most appropriate implementation to get the best performance for the particular use case.</p>
<p>There is a subtle difference between the two, but the second IMO is a cleaner, more-flexible solution.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/objectopia.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/objectopia.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/objectopia.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/objectopia.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/objectopia.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/objectopia.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/objectopia.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/objectopia.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/objectopia.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/objectopia.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/objectopia.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/objectopia.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/objectopia.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/objectopia.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=7&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://objectopia.com/2009/05/20/non-anaemic-models-and-service-oriented-architectures/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ea90ab2b972631952cf64bb4228e6f76?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">chris</media:title>
		</media:content>
	</item>
		<item>
		<title>Re: A general approach to exceptions in Java</title>
		<link>http://objectopia.com/2009/03/23/re-a-general-approach-to-exceptions-in-java/</link>
		<comments>http://objectopia.com/2009/03/23/re-a-general-approach-to-exceptions-in-java/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 01:03:00 +0000</pubDate>
		<dc:creator>Chris Burnley</dc:creator>
				<category><![CDATA[Java etc...]]></category>

		<guid isPermaLink="false">http://objectopia.wordpress.com/2009/03/23/re-a-general-approach-to-exceptions-in-java/</guid>
		<description><![CDATA[My previous post about exceptions in Java begs the question: Where do so called &#8220;business exceptions&#8221; fit in with all of this? Business Exceptions are Checked Exceptions Following on from my reasoning, the user is something that you have no control over. Therefore you expect these types of exceptions to occur. Making them checked exceptions [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=5&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>My <a title="General Approach Exceptions in Java" href="http://objectopia.wordpress.com/2009/03/22/a-general-approach-to-exceptions-in-java/">previous post</a> about exceptions in Java begs the question: Where do so called &#8220;business exceptions&#8221; fit in with all of this?</p>
<h2>Business Exceptions are Checked Exceptions</h2>
<p>Following on from my reasoning, the user is something that you have no control over. Therefore you expect these types of exceptions to occur. Making them checked exceptions forces you to handle them in some way.</p>
<p>A classic example of these errors are validation errors. These should be checked exceptions because usually you&#8217;d need to force the user to fix the entered data before the form can be submitted.</p>
<h2>Dealing with Checked Exceptions</h2>
<p>The problem of checked exceptions is: how do you handle them ? You&#8217;ve got to catch them somewhere (or rethrow), how do you know what to do with them ? This is usually a requirements question; this should be a hint to you to go back to the business and get some clarification on the requirements.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/objectopia.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/objectopia.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/objectopia.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/objectopia.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/objectopia.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/objectopia.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/objectopia.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/objectopia.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/objectopia.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/objectopia.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/objectopia.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/objectopia.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/objectopia.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/objectopia.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=5&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://objectopia.com/2009/03/23/re-a-general-approach-to-exceptions-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ea90ab2b972631952cf64bb4228e6f76?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">chris</media:title>
		</media:content>
	</item>
		<item>
		<title>Persistent Strategies</title>
		<link>http://objectopia.com/2009/03/22/persistent-strategies/</link>
		<comments>http://objectopia.com/2009/03/22/persistent-strategies/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 21:51:00 +0000</pubDate>
		<dc:creator>Chris Burnley</dc:creator>
				<category><![CDATA[Java etc...]]></category>

		<guid isPermaLink="false">http://objectopia.wordpress.com/2009/03/22/persistent-strategies/</guid>
		<description><![CDATA[I&#8217;ve just finished working on a cash management system. The core of what the system does is listen to messages produced by various sources and record a transaction (i.e. a debit and a credit) between two accounts. For example, the system will listen to trade messages produced by our trading system and charge a trade [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=4&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just finished working on a cash management system. The core of what the system does is listen to messages produced by various sources and record a transaction (i.e. a debit and a credit) between two accounts.</p>
<p>For example, the system will listen to trade messages produced by our trading system and charge a trade fee to the client. This involves debiting the client and crediting the Fee house account.</p>
<p>This seems innocent enough, but to create a transaction you must have a reference to each of these accounts.</p>
<p>The client’s account is easy enough to find as all the required information is supplied in the trade message. But what about the house account ? How does the system find an instance of the house Account ?</p>
<p>One could do something like this, store the account number in a constant somewhere:<br />
<pre class="brush: java;">
Account account = accountService.getAccount(FEE_HOUSE_ACCOUNT_NUMBER);

// create Transaction with client and house account
</pre></p>
<p>This is pretty bad IMO because there is duplication and &#8220;hard coding&#8221; ( even if it is in a properties file) of what house account numbers there are.</p>
<p>If you didn’t want to store the account number in code (or in a properties file which is almost as bad) you could add it to the static data for that transaction type:<br />
<pre class="brush: java;">
@Entity
class TransactionType {
    String name;
    Account creditAccount; // this could be null to indicate that the account is based on the message
    Account debitAccount; // this could be null to indicate that the account is based on the message
    //...
}
</pre></p>
<p>then you would just find the TransactionType and the get the credit or debit account.</p>
<p>This would work, but it is very specific, since sometimes we may want to find the debit / credit account in a different way (e.g. “find the loan account associated with the client’s cash account”).</p>
<p>Enter the <strong>Persistent Strategy</strong>.</p>
<p>Basically, the idea is that rather than store links directly to Accounts in your static data, store a Strategy to obtain the right Account.<br />
<pre class="brush: java;">
@Entity
public class TransactionType {&lt;/code&gt;

    private String type;

    @ManyToOne
    private AccountAllocationStrategy toAccountStrategy;

    @ManyToOne
    private AccountAllocationStrategy fromAccountStrategy;
}

@Entity
@Inheritance
public abstract class AccountAllocationStrategy {
    public abstract Account getAccount(Transaction transaction);
}
</pre></p>
<p>What we’ve done is added a strategy for find the from / to account and we can have specific implementations:</p>
<p><pre class="brush: java;">
@Entity
public class FixedAccountAllocation extends AccountAllocationStrategy {

    @ManyToOne
    private Account account;

    public Account getAccount(Transaction transaction) {
        return account;
    }
}

@Entity
public class InvestorAccountAllocation extends AccountAllocationStrategy {

    @Override
    public Account getAccount(Transaction transaction) {
        return transaction.getInvestorAccount();
    }
}
</pre></p>
<p>(there are a few more implementations I&#8217;ve left out for brevity).</p>
<p>You could achieve a similar effect by using a code of some sort (e.g. an enum) to denote the strategy and look up the strategy instance via Spring, but I like this better since it is more transparent and doesn’t require involving other frameworks. The major problem with the Spring approach is you’ve still got to specify the account numbers somewhere in your Spring context file which is duplication (once in the Spring file, once in the database) which, we all know, is bad <img class="wp-smiley" src="http://emgtech.macbank:8080/emgblog/wp-includes/images/smilies/icon_smile.gif" alt=":)" /></p>
<p>It might seem like abusing entities or the domain model but it is a really powerful pattern. Think of these entities as your rule domain. JPA makes mapping entities really easy and the number of strategies are finite so you can be quite creative in your mapping and inheritance hierarchies. You can also fully cache the strategy entities so performance will not be an issue.</p>
<p>We use this pattern in a few places in the system and it has made the code much cleaner and maintainable.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/objectopia.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/objectopia.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/objectopia.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/objectopia.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/objectopia.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/objectopia.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/objectopia.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/objectopia.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/objectopia.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/objectopia.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/objectopia.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/objectopia.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/objectopia.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/objectopia.wordpress.com/4/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=4&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://objectopia.com/2009/03/22/persistent-strategies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ea90ab2b972631952cf64bb4228e6f76?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">chris</media:title>
		</media:content>

		<media:content url="http://emgtech.macbank:8080/emgblog/wp-includes/images/smilies/icon_smile.gif" medium="image">
			<media:title type="html">:)</media:title>
		</media:content>
	</item>
		<item>
		<title>A general approach to exceptions in Java</title>
		<link>http://objectopia.com/2009/03/22/a-general-approach-to-exceptions-in-java/</link>
		<comments>http://objectopia.com/2009/03/22/a-general-approach-to-exceptions-in-java/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 21:42:00 +0000</pubDate>
		<dc:creator>Chris Burnley</dc:creator>
				<category><![CDATA[Java etc...]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://objectopia.wordpress.com/2009/03/22/a-general-approach-to-exceptions-in-java/</guid>
		<description><![CDATA[Checked vs. Unchecked Exceptions in Java. The topic is pretty much as controversial as it comes. The debate over when to use a unchecked (those that are subclasses of java.lang.RuntimeException) vs. a checked (those that do not extend RuntimeException) is as old as Java itself. I’ve witnessed many a debate over the topic over the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=3&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Checked vs. Unchecked Exceptions in Java. The topic is pretty much as controversial as it comes. The debate over when to use a unchecked (those that are subclasses of java.lang.RuntimeException) vs. a checked (those that do not extend RuntimeException) is as old as Java itself.</p>
<p>I’ve witnessed many a debate over the topic over the years. When to use unchecked ? Are checked exceptions even a good thing ? Everyone has a different opinion on the subject so I’ll attempt to explain a general approach that hopefully will be helpful to decide when to use one type of exception over the other.</p>
<p><strong>Both checked and unchecked exceptions are useful</strong></p>
<p>Yes, both exception types are useful. You will sometimes find extremes of people who will only use one or the other, but by doing this you will not be able to benefit from the unique properties of each type: Unchecked exceptions don’t obviously have to be declared as part of the method signature, so the exception does not need to be handled or exposed in all the method signatures up the call stack. Checked exceptions are the opposite, they force the caller to either deal with the exception or inform its caller that it needs to deal with it and so on. These are both unique characteristics that are useful in different circumstances.</p>
<p><strong>When to use each type</strong></p>
<p>Exceptions are thrown because there is some sort of error that the system cannot deal with. An error can be categorised as either “there is an error in the code” or “there is an error with the system’s operating environment”. These two categories can can distilled into “an error that can be prevented”, vs. “an error that the system has no control over”.</p>
<p>So, if the system was perfectly designed, i.e. no bugs, then the first type of exception (an unchecked exception, an error in the code) should never occur. These are RuntimeExceptions, since there is no point bothering the caller of your object with errors that should not occur ! Examples of these are NullPointerException (check for null !), ArrayIndexOutOfBoundsException (check the length of the array !) etc.</p>
<p>The other type of exception, checked exceptions, are completely out of the control of the system and clients should be forced to deal with them. Examples of these are JDBCException (you can’t control whether the database will be available), FileNotFoundException (sure, you can check to see if a file exists, but you can’t guarantee it’ll be there when you read it) and RemoteException (you can’t ensure that the remote service will be available or bug free).</p>
<p><strong>Perfect code vs. perfect environment</strong></p>
<p>So, in summary I follow the following rules: use unchecked exceptions for errors that can be prevented and checked for those that cannot. It can also be thought of like this: If you have perfect code there should be no runtime exceptions. If you have a perfect environment there should be no checked exceptions. Obviously neither of these are possible, this is why we need both types of exceptions.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/objectopia.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/objectopia.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/objectopia.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/objectopia.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/objectopia.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/objectopia.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/objectopia.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/objectopia.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/objectopia.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/objectopia.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/objectopia.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/objectopia.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/objectopia.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/objectopia.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=3&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://objectopia.com/2009/03/22/a-general-approach-to-exceptions-in-java/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ea90ab2b972631952cf64bb4228e6f76?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">chris</media:title>
		</media:content>
	</item>
	</channel>
</rss>
