Lately I’m talking a lot about refactoring.
When I do, I use a lot a metaphor I have learned from Vera Peeters and Pascal Van Cauwenberghe.
Refactoring is like cleaning a kitchen.
If you observe the kitchen of a restaurant, you will see that they are cleaning the kitchen all the time.
So cooking and cleaning at the same time. (In other words I see refactoring as part of doing development)
Nobody would accept a cook to enter the restaurant and say: today the steak is 20 euro’s more expensive as we have to clean the kitchen first.
(And I presume that is when most people talk about refactoring and want a lot of money/time for it. They talk about doing a big refactoring that is more a rebuilding the kitchen instead of cleaning.)
Neither would a cook accept that I go into his kitchen and say: I want my steak half the price, can’t you not clean the kitchen today?
In the software world we let people tell us, do it quick and dirty, you can clean up after, when we have the time.
They presume it goes faster to build dirty code. Does it go quicker to cook in a dirty restaurant?
The big question is of course what to do when the kitchen is in a big mess?
(or what do you do when the code is in a mess)
There I say – use the boyscout rule: leave the place nicer than what you found.
In other words, do a little bit of refactoring to clean the code up every time you add something.
As we don’t want things to break, for me this would be start by adding unit tests.
To do this, I don’t think a team needs the approval of a manager.
A good book that helps people to learn about these first steps is Working effectively with legacy code. I recently started yet another book Reading club at a client with this book.
I’ll write more about this in a future post.
Update: Another good book is Refactoring to patterns
Second Update: Joshua created a google group around metaphors, I hope you join the discussions around metaphors.
Third Update: Joshua is also the inventor of the Limited Red Society
9 comments on “Cleaning a kitchen is a good metaphor for Refactoring”
I think the ‘What to do when the kitchen is a big mess?’ analogy works well. Can you imagine what the maître d’ would say if the chef told him: “No covers today, we’re shutting down to clean the kitchen”. Apart from some colourful language, I’m pretty sure the outcome would be: Clean up as you go, but we have to serve the customers.
A friend of mine is a cook. I told him that developers and managers alike in software development don’t clean up. His reply was unambiguous. Cooks do it. They don’t even think about it. It’s part of their training and procedures.
Thank you for your post. It *is* an excellent metaphor!
Thank you @Olivier
yes that is why I keep saying to developers it’s their responsibility to clean up and to add tests etc…
The complained “we don’t have time” is just plain wrong.
As if “we don’t have time to compile” would accepted…
y
Bob Marshall tweeted:
We only have to watch Ramsay’s Kitchen Nightmares to see appaling “technical debt” in many restaurant kitchens. :}
Actually for me I think we have cleaning at multiple levels.
1) While cooking.
2) At the end of the evening
3) A larger cleanup on the weekday the restaurant is closed
4) A big cleanup once a year during holiday.
What are the levels you use in your code?