The Limited Red Society – Joshua Kerievsky
I recently watched a presentation given by Joshua Kerievsky from the Lean Software & Systems conference titled 'The Limited Red Society' in which describes an approach to refactoring where we try to minimise the amount of time that the code is in a 'red' state.
This means that the code should be compiling and the tests green for as much of this time as possible .
I think it's very important to follow these principles in order to successfully refactor code on a project team and it's an approach that my colleague Dave Cameron first introduced me to when we worked together last year.
These are some of my observations and thoughts on the talk:
- Kerievsky talks about parallel change which is where we want to make some changes to a bit of code and instead of changing it directly we create a parallel implementation and then gradually change the clients of that code to use the new approach.
An example of this which I wrote about last year was when we wanted to move the creation of objects from using object initializer to the builder pattern. Instead of doing it all in one go we had both approaches in the code base at the same time and gradually moved all the existing code to use the new approach. We also tried to use this approach to change the API of one of the main objects in the CC.NET code in a dojo last year.
Kent Beck talks about a similar approach in his QCon talk titled 'Responsive Design' from November 2008.
-
One interesting point that Josh made in the Q&A session is that there may be times when we don't necessarily want to go straight for parallel change – it might be easier to use a narrowed change approach first.
With narrowed change we would first look to reduce the number of places where we have to make the change we want to make.
For example if we want to change an object to internally use a list instead of an array we could first isolate the places where we add to or retrieve from the data structure into methods. We would then call those methods instead of accessing the data structure directly.
This way we can reduce the number of places we need to change when we eventually change the array to a list.
I haven't used this approach before but will look to do so in future.
- There was a discussion about small steps and big leaps at the end where one of the attendees pointed out that it often takes much longer to take a small steps approach rather than just taking one big leap.
Josh pointed out that the appropriate choice depends on the risk involved in the refactoring situation – if it's low risk then perhaps it does make sense to just change the code in one go. However, an additional advantage of the small steps approach is that it makes it much easier to do a graceful retreat if the refactoring gets out of hand and we end up yak shaving.
Although I already knew some of the approaches shown in this video it's always interesting to see how experienced practitioners put them to use and there were a couple of new ideas that I hadn't come across before.
I particularly liked the fact that there was a 20 minute Q&A section at the end. The discussion is quite interesting to listen to.
[...] This post was mentioned on Twitter by Mike Cottmeyer. Mike Cottmeyer said: Interesting Post… The Limited Red Society – Joshua Kerievsky http://dlvr.it/2Ks5L [...]
Tweets that mention The Limited Red Society – Joshua Kerievsky at Mark Needham -- Topsy.com
5 Jul 10 at 7:53 pm
First, congratulations for the always very interesting posts.
Regarding the narrowed change approach that is mentioned above, I got the impression that we are talking of nothing more than the good old OO encapsulation. If so, for the sake of enforcing limited redness, the choices actually are between the big leap (of faith) versus the more controlled "localized deltas".
In either case I think that the difficult bit resides in the anticipation of the unavoidable ripples – and in knowing where the ripples will be triggered. What made me think of a another use for the Mihado-ish visualization methods.
Regards
Claudio Oliva de Lyra
6 Jul 10 at 6:05 am
@Claudio – hmmm that's true actually, hadn't considered it that way. Although I would say it's information hiding within a class i.e. we're hiding the storage mechanism to all other methods inside our class.
I don't usually do that but maybe I should!
I think that Mikado would be useful for seeing whether we need to narrow the change in the first place and if there aren't many places to change then perhaps we can just go ahead and make the change straight away.
Mark Needham
7 Jul 10 at 7:09 am
[...] example Joshua Kerievsky has come up with some names to describe incremental refactoring techniques such as parallel change and narrowed [...]
The value of naming things at Mark Needham
31 Jul 10 at 7:06 am
[...] Incremental refactoring is a concept that Dave Cameron introduced me to about a year ago and it's been talked about recently by Kent Beck and Joshua Kerievsky. [...]
Coding: Tools/Techniques influence the way we work at Mark Needham
7 Aug 10 at 1:14 pm
Nice post- shame there's no retweet button :}
- Bob
Bob Marshall
8 Aug 10 at 5:58 pm
Good idea – have installed the sociable plugin now!
Mark Needham
8 Aug 10 at 6:16 pm
[...] of direct field references which will make it easier to change the underlying implementation. Kerievsky's narrowed change refactoring suddenly becomes less [...]
Ruby: Accessing fields at Mark Needham
22 Aug 10 at 6:26 pm