eXtreme Wednesday: Offset or Index?
First off, a big thank you to all the people who have been commenting on the eXtreme Wednesday postings. I appreciate that you take the time to look at my little piece of cyberspace.
Due to the Edinburgh Festical currently being in full swing, it was decided to move our venue for the duration of the festival to the bar in Ocean Terminal. Feel free to come along to our temporary venue if this is more convenient.
We were depleted in numbers this week due to a variety of reasons or should that be various excuses! Abdel has indeed used the “getting married” and “on honeymoon” excuse for not turning up, Colin Mackay finds it difficult to get across Edinburgh to the temporary venue and Brian Swan is enjoying the festivities going on throughout Edinburgh. Jon Mountjoy is an occasional visitor, so we don’t count him as being an absentee when he doesn’t turn up! Although we were few in number, it was a brilliant session for a number of reasons.
We decided that we’d had enough of attempting to write tests for GUI type code and would do something different this week. However, we still would be doing something for use within the project. To put it simply it was decided upon to code up a list manager. A typical use for it could be a “To Do” list and a “Done” list that has “Do” and “Undo” actions attached.

The “ListManager” class was built up through a number of refactorings. We started with the ability to add items to the “to do” list, moved on to build functionality that could select / deselect an item and evolved into an action to transfer from the “to do” list to the “done” list. At this stage we only had tests and code that could do single selections. A major refactoring later we had multiselection all working and a green Junit bar.
The lines of code count for the session ended at:
92 lines of test code
80 lines of “real” code
We had an interesting discussion on how to reference (index) items in a list such as the one being built. Do we just use the item value and avoid duplicates? Or do we handle the possiblity of duplicates? Or do we have a unique indentifier for each list item?
Next week see us trying to implement this with some form of GUI front end. Oh no! Back to the world of GUI testing…
Throughout the night, we had a few occasions to prompt Andy, whom was so immersed in the art of writing lines of code, that he had missed some of the higher level thinking that is part of the test and code writing process. The key point to this is that Test Driven Development (TDD) isn’t easy and even experienced people require the support offered to them through pair (or threesome) programming buddies. Our combined talents ensured we had a comprehensive list manager and test suite at the end of the evening.
One of the most interesting discussions was on the use of the term “Index”. It has commonly come to mean anything that has 0 (zero) or 1 (one) starting base. Andy pointed out that in purist forms:
But, Java arrays are zero based and Sun have decided that all parameters refer to in the documentation are referred to as “index”. Shouldn’t they have used offset there? Does this now mean we should use offset correctly when programming in a language that doesn’t following the correct definition? Well this is a difficult one for us perfectionists, but in this case it is better to follow the convention being used in the language and project, so “index” it is for us!


