Good examples when teaching refactoring?

Here are some codes, both the original and the refactored version, so you can prepare your kata or simply compare the results once the refactoring is performed:

  1. My books have both shorter examples and a longer, actually a book long example. Code is free to download.
    VB Code Examples
    C# Code Examples

  2. A nice example from Refactoring Workbook

  3. There are a lot of examples on the internet of simple games like Tic-Tac-Toe or Snake that have a lot of smells but are simple enough to start with refactoring.


I would actually suggesting refactoring some of your and your coworkers' code.

There are always places that an existing codebase can be refactored, and the familiarity with the existing code will help make it feel more like a useful thing and less like an exercise. Find something in your company's code to use as an example, if possible.


The first chapter in Martin Fowler "Refactoring" is a good starting point to refactoring. I understood most of the concepts when one of my teachers at school used this example.

Tags:

Refactoring