This morning I was going through some code that my team and I wrote a couple of weeks ago. We had violated DRY in an attempt to show a client (who wanted to show a venture capitalist) our progress (sort of by faking it, I guess). It seemed necessary at the time (and I still think it was), and it worked fine.
In any case, I promised myself that before this iteration was over, I would refactor the code, because I didn't want it to become a nightmare to maintain. I started out trying to get the whole thing in one go. When I was almost done, I suddenly noticed "there's no way this is going to work." I had removed some code that was needed for another piece to work, and couldn't remember what the code was - I just noticed it was missing.
It was Javascript as well, so it's not like it would have been incredibly easy to figure out what the problems were, had I continued along my path.
Anyway, I started over, taking baby steps - one small bit at a time, while ensuring what existed still worked. It helped a bunch.
So, the lesson is: As while coding in general, it is important to take baby steps when refactoring.
Hey! Why don't you make your life easier and subscribe to the full post
or short blurb RSS feed? I'm so confident you'll love my smelly pasta plate
wisdom that I'm offering a no-strings-attached, lifetime money back guarantee!
Leave a comment
I do the opposite! Get a big knife and hack that cancerous code clean out.
Ok, maybe it's not that extreme, but I do like to see huge stonking errors and not subtle ones as I refactor.
Posted by
Adrian Lynch
on Dec 25, 2007 at 01:56 PM UTC - 6 hrs
Ack! That sounds like rewriting. =)
The small steps don't typically have errors more subtle than your normal ones. The point of taking the baby steps is that you make one small change, then ensure it still works.
If it doesn't, fix it until it does.
By taking the larger step before testing, when it breaks, you can't be sure where - just somewhere in that big knife cut. That's why I feel it is more like a rewrite - which of course is an acceptable solution to many problems.
Posted by
Sammy Larbi
on Dec 27, 2007 at 10:19 AM UTC - 6 hrs
You've read The Pragmatic Programmer haven't you? :OD
I see you point. I don't think I've got my terms nailed down.
Posted by
Adrian Lynch
on Dec 27, 2007 at 03:46 PM UTC - 6 hrs
No, but it is on my desk in queue waiting to be read =).
I have read several related things though, and Refactoring is on my list and desk as well. I hope to devote a bit more time for (non-school-related) reading in the new year though. =)
Posted by
Sammy Larbi
on Dec 27, 2007 at 04:06 PM UTC - 6 hrs
Oh definitely make time for PP!
My two favourite work related books - The Pragmatic Programmer and Hackers & Painters.
http://www.adrianlynch.co.uk/books.cfmI've read them both more than once.
Posted by
Adrian Lynch
on Dec 27, 2007 at 05:00 PM UTC - 6 hrs
Leave a comment