Clean Code Clinic: Refactoring Fest

room: Osgoode Foyer, LC — time: Wednesday 14:00-15:30, Wednesday 16:00-17:30
Average Rating: -

Intent

Provide the participants with a hands-on-experience of real world refactoring by taking an open source project and refactoring it.

Summary

Refactoring is a very well established practice not just in the Agile Community, but outside as well. Following are some of the books that have been published on this subject:

  • Refactoring: Improving the Design of Existing Code: Martin Fowler
  • Refactoring to Patterns: Joshua Kerievsky
  • Working Effectively with Legacy Code : Michael Feathers

Unfortunately, in-spite of such great knowledge available, there are lots of misconceptions around refactoring. The word “refactoring” is often used in a broad context where “enhancement” or “rewrite” would be a better term, and can cause nightmares to project stakeholders.

This session is an attempt to help the development community understand refactoring a little better. It will provide a hands-on opportunity for developers to explore these concepts in action. This session will try to amplify the participant’s learning process by pairing them with other practitioners and peers.

Intended Audience

This session is suited for developers and architects who are interested to learn how to refactor real projects.

Benefits

After attending this session, the participants should be able to:

  • Build a common vocabulary in the refactoring space
  • Identify code smells
  • Eliminate code smells by applying the simple refactoring techniques explained in Martin Fowler‘s “Refactoring”
  • Write better unit/functional tests for legacy code
  • Understand some of the techniques and pitfalls in refactoring legacy code in the absence of unit and functional tests [”Working effectively with legacy code “]
  • Take existing code and refactor it to standard design patterns [Refactoring to patterns]
  • Learn about the internals of the open source project chosen to refactor
  • Know where to look to continue learning the techniques of refactoring

History of this workshop

Process/Mechanics

Outline Section 1 – 90 Minutes

Iteration 0 / Overview : 45 mins

  1. 20 mins: Quick overview about refactoring with some examples.
  2. 10 mins: High level overview of the open source project‘s design
  3. 05 mins: The participants form pairs and each pair picks up a module/package of the open source project.
  4. 10 mins: The participants spend time understanding the functionality of the module/package picked up by the individual pairs.

Iteration 1 : 45 mins

  1. 10 mins: I’ll show 2-3 simple code smells, explain associated refactoring techniques.
  2. 15 mins: Each pair identifies one or more classes from the module/package, which has these code smells. They try and understand what it does, in the process they might do some basic refactorings like extract method and rename variables/methods. Eventually the goal is to writes one or more unit tests around it. Once they have sufficient passing unit tests [safety net], they start cleaning up code by applying some advanced refactoring techniques. In some cases, sufficient unit tests might not be required to do simple refactoring like extract method, rename variable, etc. Sometimes internally restructuring the code, can help us understand it better. Hence the participants will have to constantly switch between ‘understanding’, ‘unit testing’ and ‘refactoring’ hat.
  3. 20 mins: The pairs stops refactoring. Couple of pairs connect to a central project and demonstrates their accomplishment to the rest of the group. We can break into a discussion about each team‘s refactorings.

Break – 30 Minutes

Section 2 – 90 Minutes

Iteration 2: 40 mins

  1. The pairs swap partners so that each team gets a new member and one old member continues on the selected module/package.
  2. 10 mins: I’ll show 2-3 little more complicated code smells and explain associated refactoring techniques.
  3. Pairs try to apply these refactoring techniques for the next 15 mins.
  4. At the end of 15 mins we have another 15 mins demo and refactoring discussion.

Iteration 3: 40 mins

  1. The pairs swap partners again.
  2. 10 mins: I’ll show 2-3 more complicated code smells and explain associated refactoring techniques.
  3. Pairs try to apply these refactoring techniques for the next 15 mins.
  4. At the end of 15 mins we have another 15 mins demo and refactoring discussion.

10 Minutes - Retrospective

  • What worked? The participants indicate what they learned.
  • What did not work?
  • What to do differently next time? Suggestions from participants on how to improve the session.

Infrastructure Required

  • U shaped table setup with a projector at the center of the table which can connect to all the computers.
  • Either the participant get their own laptops with required software setup or we provide the participants with computers. We’ll need 10-15 computers for the participants. Each computer is set up for a pair [2 chairs]. The presenters will set up the computers with the required software a day in advance of their session.
  • 10-15 flip charts, one per team.

Pre-requisites for attending the session

  1. Object Oriented Programming
  2. Some knowledge of Java and Servlets [don’t worry too much about this, pairing can save you]
  3. You need the following software setup on your machine before you come: