Skip to content


The Meaning of Guru

Today I met one of the managers of the development team I work with in India. I was chuffed to learn some people call me “The Guru” over there. The manager went on to mention the etymology the word:  ‘Guru’ is composed of the syllables ‘gu’ and ‘ru’, the former signifying ‘darkness’, and the latter signifying ‘the destroyer of that [darkness]‘, or the ‘bringer of light’. My own manager quipped that the light in question was actually the reflections off my head (probably a fair call, but I actually think the light shines forth from another orifice).

Posted in General.

XPDay 2009

I’ve just registered for XPDay 2009. I last went to XPDay 2005, and had a blast. I regret not going back since, but I’ll be there this year, at least!

Posted in Agile.

Singletons are Evil 2: the Rant

I’ve wrote about this before, but singletons really are evil. It’s worth repeating, as I’m finding out that the message hasn’t really reached a lot of people yet.

I’ve been helping out with interviewing candidates for a senior developer/technical lead/technical architect role at my current client. To my dismay, there is a very consistent problem across all the canditates I’ve met: they all like the Singleton pattern. The converstation usually runs along these lines:

Me: Can you name any design patterns?

Candiate: Singleton
(they will usually name a few more patterns, but Singleton is almost always the first one named)

Me: Can you tell me about the pros and cons of Singleton?

Candidate: They’re really useful, I use them all the time! They ensure that you only have a single instance of an object at any one time. Also, you don’t need to pass references to them, because they can be accessed directly.

Me: OK, are there any problems with the use of singletons?

Candidate: Umm… you can sometimes get multiple instances if you use multiple JVMs.

I’m starting to use this as a weeder question in interviews now. I don’t care if your resume says you have 8 years of experience in enterprise Java. If you’ve got that much experience, I’m hoping you’ve heard (or discovered yourself) that Singleton make code brittle and harder to maintain. I don’t mind if you use Singletons on rare occasions (I do it myself sometimes), but you really need to be fully aware of the problems that they cause.

You can view my previous post for a list of links with more details, but in summary, some of the problems are:

  • You lose control over memory management. It’s basically a resource leak.
  • It promotes tight coupling. Need an implementation? Go to the singleton over there! However, by hard coding the singleton class, it makes it harder to mock, stub out or otherwise change.
  • It hides dependencies. It is harder to spot from the public methods of a class that it makes use of a singleton service.
  • By mixing the responsiblities of providing a service, and managing the object lifetime (badly), a singleton violates the Single Responsibility Principle. If you only want a single instance of a class, create one at the start of the program and pass it objects that need it. If you use something like Spring, you can even declare in configuration that an object is a singleton. No need to hard code that policy in code!
  • A Singleton in a multithreaded environment can be tricky. Make sure that you handle all the edge cases!
  • As Stevie says, the Singleton “pattern” encourages you to forget everything you know about OO design, since OO is hard, and procedural is easy.

There are more problems, but that’s a good start.

Posted in General.

Kanban at XtC

I’ve just noticed that the Extreme Tuesday Club is has Kanban presentations tomorrow (29th September). Given I’m a complete newbie on anything Kanban, I’ll definetly turn up to that one.

Posted in General.

ASL Compatability Policy

An astute reader asked if the Ant Script Library will be updated to make use of any of the new features that will be available in the upcoming Ant 1.8 release. New features include enhancements to boolean properties, the import element to support optional imports, and new features such as include and target group. Many of these features can help simplify complex build scripts, and could make a big difference to something like the ASL (indeed, EasyAnt has been a driver behind some of these features).  So when Ant 1.8 is released, will I make use of these new features?

Short answer: No

Slightly longer answer: Not yet.

Long answer: As a matter of policy, after Ant 1.8 is released, I will avoid making use of any 1.8 specific features for a relatively long period. I will definitely make sure that the ASL is fully compatible with Ant 1.8, but it will still be fully compatible with Ant 1.7.

This is because the ASL is intended to be used as an add-on library to an existing ant infrastructure. However, in my experience many companies and IDEs are quite conservative in upgrading their Ant installations. Probably in a year or two after Ant 1.8 is released, I might feel comfortable in adding dependencies on the latest features (probably keeping a 1.7 compatible branch of the ASL available for a longer time). By that time I expect that Ant 1.8 will have made inroads to corporate build installations and IDEs. However, I’ve worked in places where Ant 1.7 (now 3 years old!) is still under consideration. If history is anything to judge, there will be a long period before Ant 1.8 makes it into some development shops.

I would regard this as probably the major difference in philosophy between ASL and EasyAnt:

  • EasyAnt is a replacement for Ant. It extends the internals of Ant to add non-standard features (e.g. “phases”). It is invoked by calling a completely different front end script. It contains an embedded and modified version of Ant, which must be installed separately. This gives them the freedom to make full use of new features, but it means a full switchover is required.
  • ASL is less ambitious (it’s just a library), but I think it makes it easier to accept in more conservative organisations that are happy with Ant, but are looking for a way to control build script complexity. For this reason, the ASL must be more conservative, too (though I might end up having two versions of the ASL, one for Ant 1.7 and another for Ant 1.8)

Posted in Build Automation.

CITCON ‘09: Better Ant Builds

The first session I attended (and partially ran) was Better Ant Builds.

During the session proposals, Ivan Moore originally suggested a talk on better builds for Java programs. There were later proposals for sessions regarding improvements to Maven, so I proposed my own session “Better Ant Builds” to differentiate it from the Maven sessions.

My main goal was to promote by own contribution to this area: the Ant Script Library. JTF knew about this, and asked some leading questions when I proposed the talk about my library, which I thought was funny. I thought it would have been a bit too cheeky to give a great big marketing pitch, but then again I’m not the best marketer. Thanks for the push, Jeff!

Despite there being no projector available, I was able to talk a fair bit about the ASL, along with some of it’s background and design. People seemed interested, which I’m taking as a good sign. I won’t go into details, the website already has everything I discussed.

Jeff also pointed out the Ant Master Build Scripts, which at a glance seems to be a very similar project to the ASL. Looking at them, I’m pretty impressed. The author of those scripts presented a session at JavaOne called “Object Oriented Ant Scripts for the Enterprise“, which I think nails the leading design principles for reusable Ant scripts. I’d say the the master build scripts have a higher emphasis on J2EE projects, which the ASL leans more to building Java libraries, applications and static analysis. Plenty of room for both projects to grow!

The main question I had for the group was this: “How do you test an Ant script”? Historically, this has not been a problem. You wrote a script for a specific project. You ran the script, and it either worked or it didn’t. However, the Ant Script Library doesn’t have it’s own project – it is reused to build other projects. From my point of view, I really want to be able to set up an “integration test”. The answer is pretty obvious: set up a real project that you can use to run the ant script against. After running the script, you should be able to assert that artifacts are created in the expected locations. Duh! (in hindsight, anyway)

One more good tip: GitHub is a good place to set up an open source project. Another alternative might be Google Code. Currently, I’m running ASL from my own Subversion server. I’m thinking about moving to a location that can handle proper project infrastructure (version control, wiki, mailing lists, etc). Personally, I really like subversion, and I think it’s a pretty nice way to integrate ASL with your own project using svn:externals (assuming you’re using Subversion, too). Google Code uses Subversion, but GitHub uses another version control system I can’t remember (oh, wait: Git). Food for thought; I’ll think about that one for a bit.

For more details of the session, there is a write up on the wiki.

Update: The Build Doctor was actually taking good notes (as opposed to my vague recollection from 2 days later), and has a lot more detail in his own blog post on the discussion.

Posted in Build Automation, Continuous Integration.

CITCON Europe 2009

As I type, I’m listening to the final session of CITCON Europe 2009, at ISEP in Paris. Without doubt, I find CITCON to be one the most energetic and fun conferences I’ve ever attended. I think this has a lot to do with the way that the conference is run. Probably two main features that contribute to this are:

  1. The conference is run in a open space format. This virtually guarantees that the most interesting and important subjects are represented
  2. The conference is free to attend, and runs over the weekend. This has the affect that people who attend are extremely engaged with the topic at hand. Pretty much everyone who attends contributes to each discussion. There are not really any people there just to make sure that training budget is used.

A huge thanks to Jeff and PJ for starting this conference, and developing a great community around continuous integration and testing.

There were 5 sessions during the day. I’ll go into more detail about specific sessions in later posts.

Posted in Continuous Integration.

Ant Script Library 1.1.0 Released

It’s been over 6 months since the last release, so I’m well overdue for this: I’ve just released version 1.1.0 of the Ant Script Library.

There are quite a number of small enhancements throughout the library, and I’ve been filling in missing documentation, too. Here’s a summary of the major changes between version 1.0.2 and 1.1.0:

Please go to the download page if you want to try it out.

Posted in Build Automation.

Introduction to BDD

I dropped into Liz Keogh’s discussion Introduction to Behaviour Driven Development last night. It was an engaging talk, and I managed to scrawl down a page full of notes, which probably shows more about my incoherent thought process than BDD (click to embiggen):

Joe's BDD Notes

There was much more to the discussion, and I suggest you go to the horses mouth to get a proper view of what BDD involves.

Posted in General.

Detecting Cycles using JDepend and Ant

Package dependency cycles are bad, mmkay? However, it’s amazing how easy it is for cycles to accidentally appear, especially among teams of developers who may not be aware of the pitfalls. Ideally, I would like the automated build to break if a cycle appears, ensuring that the problem can be fixed up before it gets out of hand.

JDepend already reports if cycles are present between packages, but it isn’t as easy as it could be to cause the build to break. One suggestion is to write a JUnit test that runs JDepend separately, and fails if a cycle is found (see the JDepend documentation). Although possible, I don’t think it is as elegant as it could be, because:

  • I have to get the path to the compiled code into the unit test, either by hard coding the path, or possibly passing it in as a parameter somehow. This is tight coupling between the unit test and the place from which it runs.
  • I have to invoke JDepend twice: once to check for cycles, and again to generate the HTML report.

I think that an Ant script is a much better place for this functionality: it already has all the path information, all it needs is a way to find out if there are any cycles. If so, it can fail the build if appropriate. Unfortunately, the current JDepend Ant task doesn’t provide a way to find out. Until now, that is! I’ve just completed a couple of patches: one to JDepend itself, and another to the JDepend Ant task. My patch added an extra attribute to the <jdepend> element called “cyclesdetectedproperty”. This will set a property if JDepend detected a cycle. I expect that this could be used in a manner similar to this:

<target name="report-jdepend" depends="compile"
       description="Creates a package dependency report">
   <mkdir dir="${java-report.jdepend-data-dir}"/>
   <jdepend outputfile="${java-report.jdepend-data-dir}/jdepend.xml"
            format="xml"
            cyclesdetectedproperty="jdepend-cycles-found">
       <exclude name="java.*"/>
       <exclude name="javax.*"/>
       <classespath>
           <pathelement location="${java-build.classes-dir}"/>
       </classespath>
   </jdepend>

   <mkdir dir="${java-report.jdepend-dir}"/>
   <xslt basedir="${java-report.jdepend-data-dir}"
          destdir="${java-report.jdepend-dir}"
          includes="jdepend.xml"
          style="${ant.home}/etc/jdepend.xsl"/>

   <fail if="jdepend-cycles-found">Cyclical package dependencies found</fail>
</target>

I haven’t released these patches yet, but I will soon be adding it to the Ant Script Library. All going well, I’ll try and get the patches rolled back into the JDepend and Ant code bases. Let me know if you’re interested in seeing it earlier.

Update:

I just spotted the verifydesign task in AntContrib, which actually does what I would like, and more. Pretty neat, but I’d still prefer that I could fail the build from JDepend, as it is a much simpler task to configure.

<target name=”report-jdepend” depends=”compile”
description=”Creates a package dependency report”>
<mkdir dir=”${java-report.jdepend-

data-dir}”/>
<jdepend outputfile=”${java-report.jdepend-data-dir}/jdepend.xml”
format=”xml”
cyclesdetectedproperty=”jdepend-cycles-found”>
<exclude name=”java.*”/>
<exclude name=”javax.*”/>
<classespath>
<pathelement location=”${java-build.classes-dir}”/>
</classespath>
</jdepend>

<mkdir dir=”${java-report.jdepend-dir}”/>
<xslt basedir=”${java-report.jdepend-data-dir}”
destdir=”${java-report.jdepend-dir}”
includes=”jdepend.xml”
style=”${ant.home}/etc/jdepend.xsl”/>

<fail if=”jdepend-cycles-found”>Cyclical package dependencies found</fail>
</target>

Posted in Continuous Integration.