Careful with those member variables, Eugene

OOP (Object oriented programming,) or just OO, is a wonderful way of programming. I’m quite happy to say that since I’ll be honest and say I didn’t really get it properly until 2 or 3 years ago. Sure, I’ve been programming with Java and C# since 1998, but that doesn’t really mean I was doing OO all that time. A lot of people use Java or C# to write ‘object procedural’ or ‘class oriented’ programming. If you understand OO, you probably know already what I’m talking about, and if you don’t…. well I’ll try and explain.

There are a few pointers that code has not been written in the spirit of OO, and I’m going to talk about just one such small smell here. This smell is what I like to call ‘member variable madness’.

OO is to a large extent about encapsulating state. The state in OO is held in the member fields of objects. Those fields may be encapsulated data, or references to other objects. Member fields are used so that the object can keep track of data, or references, between calls to its public methods. Member fields consist of member constants (readonly in C# and final in Java) and member variables (i.e. not a constant.) Member constants are used when a piece of member data is immutable, or when a reference is a constructor-initialised dependency on another object.

Member variables are not meant to be a temporary scratchpad between public and private methods. This is not state that exists between externally stimulated method calls. What’s bad about using member variables as an internal scratchpad? I think there are at least a couple of reasons:

  • Clarity. When I look at a class for the first time, I look at its member fields. This tells me what the object is encapsulating as part of the whole program. If there are a bunch of scratchpad variables here that confuses this concept.
  • Correctness. Everytime you introduce a new member variable to a class, you are introducing another ‘degree of freedom’ of all the objects of that class. This means to be sure you haven’t broken anything you have more testing to do. Correctness can be broken in at least 2 ways:
    • Thread safety / interference. If you have 2 concurrent threads accessing one object, they will share the member variables of that object. There is a big chance they could interfere with each other leading to hard-to-find bugs
    • Initial value. If you use local variables, you know you need to initialise it every time you define it (otherwise the compiler will complain). However, with a member variable you need to only initialise it once, somewhere in the class. How do other usages know it has been initialised? Do they need to re-initialise? Might that actually break the required behaviour?

Thankfully, this smell is an easy one to fix. Simply replace the member variable with a local variable in the scope where it is initialised, then pass the variable as an argument to any other methods that require it. You may find that you now have methods with long parameter lists, but this may suggest that you need to introduce new classes to encapsulate such groups of variables anyway.

If you’re interested more in this area I recommend Ivan Moore’s ‘Programming in the Small’ series on his blog . Pair-programming with Ivan taught me more about OO programming than any other time in my career.

Sun X4500 – Taking the phrase 'disk space is cheap' to the next level

I love it when big old-school technology companies do something that surprises me. Sun’s new X4500 server does just that. It takes 48 (yes, 48) standard hard disks and puts them in a 4U server. With the 500GB hard disks available today that’s 24 terabytes in one server. That’s a frak load of disk space. To put it another way, in a 48 U rack (and the mother of all air conditioning units) that’s … umm my head can’t cope … 288 TB … What comes after ‘Terra’? When 1TB disks come out later this year, 1 rack will be over half way there.

Oh, its got 2 dual-core CPUs and (I love this bit too – very old school!) 4 gigabit ethernet ports. Reminds me of the old happy-meal cards (anyone get that?)

So what do you do with that amount of storage in just 1 server? Well apart from hosting the world’s most impressive mp3 collection, I can think of a few things:

  1. Data Warehousing gets darn cheap. Lets all start doing it! Lets never actually delete anything, just archive it to a different table. If its good enough for GMail, it should be good enough for our apps.
  2. Put your source control server on it, and check your continuous integration builds into revision control, and never have to worry about filling up the disk. Actually, scratch that one, I forgot about weblogic.jar being 17.5 GB by itself… Seriously though, this would make a great cross-department source control beast that would last for years.
  3. Give everyone huge shared and personal networked folders to work with. Turn off the quotas!
  4. Any application which is data heavy but CPU light and has separate application and database tiers could use this machine to host both tiers – no network traffic!

I’m interested to see what people do actually use it for. Such big advances can lead to interesting possibilities.

3 shells of Agile

As an agile software consultant, I’ve now been involved with quite a few clients who are either trying out, or transitioning to, agile methods to deliver software within their organization. Some of the following types of questions are frequently raised:

Do we have to be completely agile for it to work at all?

How do we start being agile?

How do we work with parts of the organization that aren’t agile?

The organization already has a strict programme management methodology – how does agile work in that environment?

In trying to answer these questions, I think it can be helpful to think of agile software development to be made of 3 shells:

Agile Shells

What this diagram shows is that we can think of breaking up all the different agile practices into 3 groups:

Agile Programming includes the development practices typically found in eXtreme Programming: evolutionary design, continuous integration, test-driven development, pair programming, domain-driven design.

Agile Projects / teams includes the agile project management and whole-team practices: short iterations, planning games, daily status meetings, information radioators, retrospectives, on-site customer proxy, acceptance-test driven requirements.

Agile Programs / organizations is referring to what happens when an agile project acts in an agile way with the bigger environment: frequent delivery to production hardware, on-site customer, frequent stake-holder meetings, agile support (e.g. from the IT operations dept.)

What I think is important is that there is strong requirement relationship looking inward, but a weaker requirement relationship looking outward. For example, if a whole program of work is going to be agile, its internal teams can’t be acting like mini waterfall projects. Similarly, the programmers on a 4 person team might well be able to practice agile programming techniques even if they don’t have an iterative development cycle.

I think breaking up agile in this way helps to answer the type of question we started out with. Some organizations might want to start with some of the more inward practices before pushing them further out. A classic example of this might be not being able to get a real on-site customer (an agile organization thing to do) but making do just with a customer proxy (which is what you’d have if you were trying to have an agile team.) Similarly, people might be willing for the team to deliver internally every iteration (maybe to UAT) but just aren’t setup to deliver to production more than once every 2 or 3 months.

Breaking up the practices in this way also helps you focus what you want to do first – it’s important to realise you might not need to be ‘completely agile‘ in one shell to support the next one out. As a first start to using agile, you might try having stake-holder meetings as part of an agile organization every iteration; have 2-week sprints, planning games, and daily status meetings as an agile team; and kick-off some technical practices like continuous integration to start out with. After a couple of iterations you’d probably find you’d need to add some more technical practices to support your iterations, and that you might need a designated customer proxy to better support the stake-holder community.

The final point to consider is how an agile project can work in the context of non-agile environmental constraints – this issue comes up frequently when introducing agile into businesses with large, dedicated IT organizations and management structures. By defining what we mean by an agile team or project, we are better able to define a strong interface between the agile team and the rest of the IT organisation. The team might need to produce relevant documentation, they might need to provide upfront requirements to other non-agile development teams. But the point is if they can’t work as part of an agile organization they can still look introspectively and find how they want to work as a team, and what technical practices they want to follow.

In closing, expecting an organization to become agile overnight is obviously unrealistic. A little analysis of breaking up the agile practices into broad areas can help transition an organization in a more controlled way.

July 7th – 1 year on

Today is the first anniversary of the London Bombings. As I blogged a year ago I was on one of the trains that was bombed, and being involved with this event has unsurprisingly had quite an effect on me and my family.

For the first few months, I tried to put the horrible things I had seen, and the fact that I had been so close to being killed or seriously injured, out of my mind as much as possible. I didn’t have nightmares or panic attacks, and I carried on pretty much as normal. I did start using the Underground again, but living in central London allowed me to use busses, or walk, much more than I had done previously. Throughout the rest of my time living in London I did go somewhat out of my way to avoid the Tube.

In November I was visiting New York and found myself on a Subway train that was stuck in a station, and the doors didn’t open. I started to feel uncomfortable, and then after a couple of minutes the doors opened and I could get off of the train. Almost immediately I started to shake violently, and felt I was going to be sick – I was having a panic attack. The feeling lasted about 5 minutes and then gradually faded, but it made me realise that I had been effected by my experiences that summer’s day in July.

I didn’t really know what to do about it though, but I did look up the London Recovers website setup by Peter Zimonjic (thanks Peter!). One of the things that came out of that was groups of survivors from each of the trains had started arranging informal self-help meetings. I went along to one of the Aldgate meetings in January and found it very useful. One feeling I had had was that I was alone – my family and friends were extremely supportive, but I didn’t feel able to share completely my experiences with people I cared about. Furthermore I had so many unanswered questions about that day. Meeting up with some of the other people on the train allowed me to talk about stuff I didn’t want to share with anyone else, and also allowed me to get a better picture in my mind of what had happened.

One particularly interesting thing I learned that day was that the ‘4 month delay’ feeling I had had was very typical. I talked to one gentleman who had actually been physically injured by the blast. For the first 4 months he had felt euphoric with the relief of being alive, but then suddenly one day his emotions had crashed. When I spoke to him in January he was getting better, but still was massively emotionally effected by his experiences.

After January, life didn’t really lend itself to doing anything more than that one meeting with the travelling I was doing. I continued to feel uncomfortable travelling on the tube, I was noticeably ‘hyper-sensitive’ to loud noises, and got very upset when I heard helicopters (due to all the choppers circling around in London after the bombs went off.) These are all classic symptoms of post-traumatic stress (PTSD), as I have since learned.

In April though I moved to New York, and one of the things a very good friend of mine made me do when getting here was to go to see a therapist – New York having suffered its own tragic events of 9/11 has a significant number of people who can help with PTSD. I’m really glad to have done this, its helped me look analytically at my feelings and thoughts. I’m now pretty much fine with the New York subway (which I use every day) and I noticed the other day that helicopters no longer seem the carriers of evil I was associating them with previously.

Today itself though has obviously been hard. I managed to take the Subway this morning (despite originally planning on walking) and it was harder than normal. A smell of burning in the office later in the morning made me pretty anxious, but it soon passed. I know today has been hard for my family too – they know how close they were to losing me last year.

Looking forward, I know that I will never forget my experience and it will have an effect on me for the rest of my life, but I know that I’m dealing with it a lot better than I did last year.

My only frustration is that we still don’t really know what happened. I know these things take time, but part of me feels there should be more publically available information to explain how and why the 4 bombers did what they did.

But to finish on a positive note, I’m incredibally pleased that in a lot of ways London didn’t change because of last year. It continues to be a thriving multi-cultural centre of the world. I hope in the years to come that Londoners remember July 7th, but as much as they can that they can live their lives as though it never happened.

Buildix – a complete SCM strategy in a free box

Buildix is a Linux distribution with a bundled source control server, issue tracker and continuous integration. In short, its a complete development server in a box, which requires almost no configuration. Even better its completely free since it uses only open-source software. And even better than that there’s a free VMWare virtual appliance (which will work with the free VMWare Server) so you can try it out with almost zero barrier to entry (apart from the download time and about half an hour to try it out.)

I’m really glad ThoughtWorks have made this available to the public – huge kudos to Chris Read, Julian Simpson and Tom Sulston for making this happen. I actually saw Buildix used on its first couple of projects before it went public and was very impressed.

Now I just need to help them get CruiseControl.NET running on it under Mono. 🙂

Update – Chris Read (one of the buildix developers) blogs more about how it came about