Sometimes You Need To Make A Class Less Detestable

A long time ago (well before I was introduced to Test Driven Design [TDD]), I used to think that tests should not really affect the way that the code is written, but I’ve really changed my stance on that. It has got to a point where classes that were not driven by tests stick out like a sore thumb. I was recently working around our ManagementAgent, a singleton that obviously written to work only when deployed into a container (on instantiation, it would require configuration that would only be available from the web.xml file).

I was in a situation where we wanted to add some more configurable attributes to a specific ManagementBean (which the Management agent would add to itself on instantiation) and I seriously saw the need to refactor some of its code. Of course without tests, I knew I could not refactor in safety. I was so revolted by the situation that I was in, that I knew it was time to make the class less detestable.

Since this class was a singleton that only worked when deployed in the container, I knew it it was time its design changed. For starters, my pair and I decided to break its singleton pattern by providing a package protected constructor and an injectable configuration instead of a self-populating one. The introduction of the constructor allowed us to easily unit test it outside of the container, while the injectable configuration allowed us to more easily test the way the agent created and added a Configuration MBean that we were so desperate to refactor.

Although it has much more work to be done to make it that much less detestable, it is one step closer to being more easily unit tested and therefore much more refactorable. On a side note, there was a huge smell that indicated the classes around the ManagementAgent were so detestable when I remembered that the package it was in had been excluded from the clover target which effectively boosted the code coverage numbers. Avoid detestable classes because it will increase the cost of future change!

Digital Camera Revolutions

PhotosI am so amazed at how far digital technology has brought us in the last few years. It was only yesterday that I remember having to get passport-like photos taken at a photo shop. The attendant would wield this large bulky camera that made four pictures from the one shot which would self-develop right in front of you. You only had one go, unless you wanted to fork out the $8 once again.

Photo stores still take them today, but no doubt, just like myself, do them with digital cameras. But why pay so much money when you can do them yourself. Not only do you get to keep taking them until you’re happy with the photos but you can even touch them up if you get really desperate. Merging many headshots into a single file is easy with any image manipulation software and transporting them to be printed on 4×6 (in either Matte or Glossy) couldn’t be easier with the wide variety of media (CD, compact flash, SD, USB drive) available. Better yet, you can get at least 8 pictures done for less than $1! Sweet.

Code Coverage Is Not The Be All And End All

My pair and I were talking about getting some code coverage results for our project (it has been a while since we have the last report because of various changes in environments and breakages caused by the move to Java 5).

We managed to finally get a report and we were talking about parts of the system that came out tested. We picked a few parts at random and it was interesting to see the different styles of tests that had been written over time. I like to think that my style of tests (at least my current style) tends to be very user-centric, aimed at representing whatever use case(s) I am working on at the time. I like to make sure that the tests I write leave behind the business reason why the code that I wrote actually exists.

In contrast to my own personal style, some of the tests we inspected seemed to actually test the structure of the code that was written instead of just the business rules. Although I was glad to see the code there was actually tested, I find that these sorts of tests (probably closer to white-box testing) are not as useful as those based on business rules (think black box testing) because I find they tend to require more changes and therefore are much more resistant to refactoring. The reason for this is that if I change to code to support a similar but different business rule, can I be confident that all the previous business rules hold as well? Probably not.

I find that some of my tests might actually end up testing a little bit of code a few more times, but I have more confidence in the system that if someone decides to change the implementation, the business will still be getting the same behaviour out of the system. Oh, and I don’t think that code coverage metrics do not add value – they certainly highlight parts of the system that need testing, but like everything else in software development, actually needs just that little bit more judgment and thought to interpret the results.

The Week In Review

This week has been a bit of a blur, and I’ve been building up quite a number of drafts but haven’t got around to posting things. I apologise for the brevity of it, but here’s at least a summary of what significant happenings have gone on recently:

  • Another Wagamama Visit – Back in March, the FOBORG gang got together to have a get together over dinner. Another few months later (has it really been three already?) on Monday we met at Wagamama’s for our next dinner. My last visit there wasn’t super-impressive but this time was much better because we had a better waiter, with the night topped off by a large dessert at Freestylers! Great seeing you (Stacey, Jason, Paul, Michelle, Karl and Caroline) all again!
  • Friday Dinner – Had Shannon, Karen, Michael and Marie over for dinner to give Suhail some more company after his big back operation. Three courser as usual including Roast Pumpkin Soup with Garlic Croutons, followed with Bourbon Chicken, a Saffron and Champagne Seafood Medley and a Butter Bean Salad finished with an excessively rich Sticky Date Pudding (inspired by the dessert other FOBORG member’s had on Monday!).
  • Aikido Grading – The rest of the week when I wasn’t preparing for the dinner was spent on training for my 6th Kyu grading that was held today. It was a really big one, starting at 1pm and finishing at 4pm, with legs starting to cramp after sitting in seiza for too long. My actual grading went quite well and I will find out the result of it this Tuesday.

Jebediah @ The Rev

Jebediah Front Man, Kevin MitchellSo I just got back from a brilliant performance by Jebediah at The Rev in Brisbane. Tonight was the 10th Anniversary Tour of the band sometimes referred to as Jebs. I remember their first CD (Slightly Odway) when I was back in high school and it was totally impressive to see this band still full of the same energy that is apparent in everyone of their albums. The Rev’s intimate size made for perfect place to host this band’s crazy grunge rock for the night, allowing for maximum exposure to the complete Jebs experience.

I turned up to the event a little bit late after grabbing something to eat after training, so I missed the first support act, Red Jezebel, who a couple of people I spoke to tonight said were pretty good. I arrived just in time to catch the second act, Neon, who also managed to shake The Rev with their classic rock riffs and tunes.

The Jebs came on about 11pm and kick-started the crowd with one of their more upbeat songs. The energy the band put into their performance was amplified and returned by the crowd, evident by the mass of arms waving and the large number of fans jumping around. Their song selection was fantastic covering most of their albums, a few B-sides and even a couple of covers songs that were lapped up by the frenzied crowd. The encore topped it all off with a couple of The Jebs’ probably most well known songs, Harpoon and Leaving Home. Although I think everyone was disappointed that the night didn’t continue past its 12:40am finish time, I think Jebediah probably made the right decision as the crowd was starting to get a little angry with excessive moshing and crowd surfing.

The Disney/Miyazaki Rort

When I read on Slashdot that Howl’s Moving Castle was being released in the USA and how well it is doing, I rushed to find out when it was going to be here in Australia (more specifically Brisbane).

Although it’s going to premiere at the 52nd Sydney Film Festival, the rest of us Aussies won’t be able to get a glance of the film until September! With broadband becoming cheaper and more accessible, and making movies that much more accessible, when will media companies raise the bar and actually compete for the consumer dollar?

So frustrating!

Politican’s Blogging?

I’ve been following Senator Andrew Bartlett’s blog for sometime and it’s really changed the way I look at politicians. The level of visibility that we get into the thoughts/opinions of the people that represent the people has always been masked by the formality of press releases and the media.

His blog gives a great insight into his real opinions and thoughts whether or not you agree with them, where there no previous ideal of getting access to them. He even presented a session in the blogging conference in Sydney last month.

Give it a read and well done Mr Bartlett for embracing blogging!