Exercises to Try


Smell Scavenger Hunt/Smell of the Week

Pick a smell and find and eliminate as many occurrences of it as you can. Every week, search for a new smell.

Re-Refactor

Pick a good- sized piece of code (either your own or one of the larger examples in the back of this book would work). Each day, start from the initial version and refactor as far as you can in 10 minutes.

Do you sense the same things each day? Do you get farther?

Just Refactor

Pick or develop a project. Spend 10 minutes refactoring. (Each day, start where you left off the day before.)

Inhale/Exhale

Find code demonstrating some smell. Apply a refactoring that addresses it. Then apply the refactoring that reverses the first refactoring. Repeat this twice more. This will give you a sense of what it's like to put a problem into code as well as take one out.

Defactoring/Malfactoring

Defactoring and malfactoring are names I use for malicious refactoring: worsening the design of existing code. Take some code and refactor it to make it as smelly as possible. (It's harder than it sounds.)

In addition to providing practice at refactoring, this may also help you realize when you're unintentionally malfactoring during development.

Be sure to restore the original after you've had your fun.

Refactoring Kata

A kata is a martial arts exercise that you repeat every day, both for practice and to help get into the rhythm of the art. (A traditional series might be a defense against four opponents.) Develop a kata for refactoring: a program where you'll apply a fixed series of refactorings. Pick a series of smells and refactorings that you see or use often; for me, that might include some Primitive Obsession, some Long Methods, some observed data to duplicate ( Duplicate Observed Data ), and some responsibilities to rebalance.

This will give you a chance to hone your editing skills and enhance your understanding of your environment, as well as to practice smelling and refactoring.



Refactoring Workbook
Refactoring Workbook
ISBN: 0321109295
EAN: 2147483647
Year: 2003
Pages: 146

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net