The Joy of Refactoring in the Green

by byamabe on January 22, 2010

I was BDDing some code for an idea I had for a Church Year website. I was using RSpec to drive the code that would return the church season based on a date. Some seasons are based on a fixed date, like Christmas, and others are relative to another date, Advent starts 3 weeks before the Sunday before Christmas. I didn’t document all the steps I took to write the code (I’m thinking of doing this as a kata), but what I wanted to point out was that at one point, I was “in the Green” and saw a bunch of duplicate code, ill-named method, and obscure variable names. I started making changes left and right while running the tests after each change and remaining “in the Green.” The experience was amazing to say the least. I hadn’t felt so proud of my code or excited about programming in a long time. I’ve always intellectually believed in the benefits of BDD, but that was the first time I’ve felt it emotionally. I can see why some people refuse to work any other way.

Comments on this entry are closed.

Previous post:

Next post: