Skip to content

Instantly share code, notes, and snippets.

@sauloperez
Created April 20, 2017 12:20
Show Gist options
  • Save sauloperez/dff2fae2b6ba44012928d4fc823b8831 to your computer and use it in GitHub Desktop.
Save sauloperez/dff2fae2b6ba44012928d4fc823b8831 to your computer and use it in GitHub Desktop.
Beat the refactoring blerch
Have you seen Matthew Inman's (The Oatmeal) comic about why he runs? It's
a classic. In it he talks about his inspiration for taking up long-distance
running. He imagines his tendency to slack off and sit on the couch as a little
creature he calls "The Blerch". It follows him around, tempting him to stop
moving and scarf down junk food.
I run too, though nothing close to the distances Inman runs. In my experience,
refactoring as a skill has a lot in common with running or any other athletic
sport. You can exercise your refactoring muscles, by deliberately working
through the steps with discipline, like we talked about in the last email. As
you get stronger, refactoring gets easier. Gnarly codebases don't seem as
demoralizing and unapproachable.
You can also slack off, and your refactoring skills will atrophy as a result.
This is especially easy if you work in an organization that doesn't have a lot
of cultural support for refactoring. The longer you go without practicing these
skills, the harder it can be to "get up off the couch" and re-start making
small, incremental improvements to your code's design.
Over the years there is one piece of fitness advice that I've heard over and
over: find pictures of people who look the way you want to look, and pin them
up where you'll see them every day. It's a perennial recommendation because it
works. Along with running I also lift weights, and I often watch workout
videos made by professional trainers, just to get inspired. Seeing people who
have trained their bodies to maximum performance reminds me of one of the
biggest reasons that I work out, and gets me fired up to hit the gym.
More than any other software skill I can think of, refactoring is aided by this
"inspiration effect". When I watch someone like Katrina Owen refactoring, it's
like my brain switches gears. I stop looking at my code as a giant overwhelming
mass, or trying to come up with a grand unified redesign all at once. I start
to fall back into the refactoring rhythm. I remember: pick up the rubber
snake, put it in the bin. Push the weight, then ease it back down. Notice data
clump, extract class. Repeat.
One great way to stay inspired about refactoring, especially if you work with
Ruby code, is with a RubyTapas subscription. Over the years I've added dozens
of refactoring videos to the RubyTapas archive. Some are recordings of
real-world refactoring sessions. Others illustrate specific design patterns or
Ruby idioms, in the context of refactoring legacy code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment