Monday, February 28, 2005

Another Bug

I've introduced another bug in my refactoring. I'm nearly to the point where I'm happy to start tackling retrofitting this thing with unit tests, but I might have to start sooner than I thought.

In some way, I do not want to stop the refactoring because of the satisfaction I'm currently receiving from the exercise. If I step back, I would realize that the satisfaction is not coming purely from the refactoring, but from what affect it is having on the design of the application; more robust and more flexible. So if I can see that refactoring too much without tests to constantly verify that I'm not actually introducing "bad things", then the refactoring is not as appealing.

From another perspective, I'm actually a bit scared to start writing unit tests. Because I don't really know where to start. So, I'll take the simple approach and start with writing the first test, which is whatever test I write first.

Sunday, February 27, 2005

Refactoring Legacy

I've decided to apply some XP practices to an old web start application. Old being from 2001, so 3-4 years. And I must say this code reeks! Which is probably a good thing. How good would it be if I pulled out this code and started admiring how it was written and designed?

I think I hacked this together in a few days. Which means there are no comments in the code and it was not well designed. But it worked. Which isn't a good thing, unless all you care about is working code (and not maintaining it). I imagine most business people think they only care about working code...

Anyway, I started with 3 classes. My first order of business was to start retrofitting some unit tests on the code. Alas, lack of design was making this near impossible without some major twister playing.

So, I started to refactor to enable fitting some unit tests on the application. And I got addicted to the refactoring! I have never gotten so much satisfaction out of writing code. But I wasn't writing code. I now have 9 commented classes, mostly between 100-150 lines of code and no new functionality, but no superfluous code either. I did manage to introduce one bug, reminding me why I started doing this in the first place.

Refactoring is good, but only with unit tests or treading very, very, very carefully. If you are going the careful treading method, my experience says get off the treading carefully as quickly as you can. Though I really don't want to at this point.

All this is given me some good insight on testing and design as well. I can see how sketching a design is a really good thing and BDUF, which is something I'm guilty of doing even on an unconscious level, is a sin. A bad sin.

Wednesday, February 23, 2005

"To sleep! Perchance to Dream."

In high school, I broke my foot while practicing the triple jump for the track team. We were practicing form and doing the step portion of the triple jump over a high jump mat. I hopped on my left foot up to the mat and did the step onto my right foot over the mat. Unfortunately my right heel just clipped the edge of the mat sending me off balance on my way down. The consquence of this was that the entire weight and force of my body was applied to the right fore foot leading to hairline fractures in the second, third, fourth and fifth metatarsals.

The first night after this, I dreamt the event all over again, up to the point where I executed the jump and jerked my leg in the land of consciousness into the wall waking myself up. My dreams immediately after the incident had no indication of the injury, but eventually my condition osmosed from the conscious world to the unconscious world.

Last night, I dreamt that I was talking to a perspective employer. And we spent quite some time discussing XP. In vivid detail. Practices. Values. Principles. Social change. Etc. That's the first time I've had such a technical dream since the time, in 1998, when I was sick in London and had fever related dreams relating to Java and the Tube.

What's it all mean? I don't know, but I woke up feeling like this was a good omen...

Tuesday, February 22, 2005

Mock Objects

Andy Marks gave a nice presentation at the local AJUG on the different Mock frameworks available. I had looked briefly at setting up a Mock framework at work to support some ugly integration testing. After having a look, I went with EasyMock, because
  1. Steve Hayes had recommended it to me when he was last here
  2. It had documentation that I could follow
But after the presentation, I'm seriously thinking that I'd prefer to go with JMock, trainwreck and all. Trouble is finding the time to get around to it (I'm not currently doing much development at work 8().

OT: It had been over a year since I last went to an AJUG meeting. Nice to see lots of familiar faces still there and a few new ones as well.

We're (Not) Going XP! 8(

Well, it has been awhile since I've had any thoughts worth recording. And that probably comes for some form of realization that we aren't really going to be doing XP.

I know XP is meant to be a best fit situation. You try a practices and refactor it, even if refactoring means that you lose the practices completely. Well, we're not going to be doing Pair Development. And we never tried it.

That is the one major practices I'm hanging out for...