Thursday, February 11, 2010

Day 26

"Do not try to bend the spoon. That's impossible. Instead... only try to realize the truth. There is no spoon. Then you'll see, that it is not the spoon that bends, it is only yourself."

I wanted to place that quote at the end, but it seemed like such a fitting introduction that it belonged at the start.

Making massive changes to your code, without changing a single line.

Often you will find yourself working on a project, when an unexpected requirement pops up and seems to demand that you perform a complete redesign or restructuring of your code. You might then find you have no idea where to start or how to proceed. You look around for awhile, testing out small changes in various places, but never getting the feel that you are going in the right direction. Finally, you stumble across an area that looks important, so you make a change that seems logical, watch as your tests fail in the way you expect, and then proceed to change your tests to fit a new criterion. However, once you get to your tests you realize that they are actually testing exactly what you had wanted them to! These tests, which are at the center of your massive overhaul, are properly testing both your old system and your new system... but you know that this is supposed to be a big change! What's going on?

This exact thing happened to me the other day. I had developed a system for weeks, carefully designing each facet, and it was almost just the way I wanted it. Then I suddenly discovered there was a fundamental change that was needed to fulfill a requirement. Not knowing where to start, I began to fiddle around in a variety of places trying to get a foothold on what I needed to do. Finally, I made a change to the code, saw a test fail, then changed the test... but the change didn't feel right. I made the change anyway, and observed the green flash before me once again. It was at that point that I realized this was all wrong. I realized that I wasn't trying to change the code at all, I was just trying to change what it meant. The massive overhaul and fundamental change that needed to occur was in my mind.

After the fact, it seemed rather obvious, but I got trapped into thinking- since my code only did one thing, it could only mean one thing. This, of course, was not the case. I was making a change that would affect every part of my system, but would change none of the functionality, just the interpretation.

I found a few signals that indicate when the change is in the theme and not in the scheme.
The biggest is that you have no idea where to make a change. You designed this system from the start and you know it inside and out, yet you can't seem to find what you need to tweak to get started on this big change.
Another is that the tests are yelling at you for trying to change them. You seem to think you know what to change, but when you make the according change to the tests it feels completely wrong. The tests seem to fight the change.
The last big one I can think of is you can't completely understand what this change means in terms of your code. You know what it should allow you to do, but you don't quite understand the new mind set you are supposed to settle into.

These three things likely indicate that either your system is already the way it is meant to be and you just need to figure out why, or that your system sucks and you should rewrite it all. It could also mean that your original problem is far more complicated that you first anticipated, but if thats the case your tests are probably screaming at you because they unsatisfied or just plain wrong.

Basically, try to remember to 'Free your mind'

No comments:

Post a Comment