Home | Shorter Path | About Me
Home
About Me

Archive

2004

01

02

03

04

05

06

07

08

09

10

11

12

 

2005

01

02

03

04

05

06

07

08

09

10

11

12

 

2006

01

02

03

04

05

06

07

08

09

10

11

12


Haunted by the Past

Sunday, February 15, 2004 11:22 PM

Anyone writing code in the real world has, at one point or another, to work on someone else's code. In such a case, a programmer's first instinct is to find some excuse to throw the code away and start from scratch. Other people's code, you know, is never properly organized, commented, or doing what it's supposed to do. Sure. Joel Splosky refers to this problem as a fundamental law of programming: It's harder to read code than to write it.

Last week I was faced with this problem, but with a twist. A customer wanted a specialized Delphi control, and I was happy to oblige. The control would be integrated into an existing library, a great deal of which I have written myself for that customer almost seven years ago. During these seven years, however, other programmers have maintained the code. And even though it was beutifully written (of course), they still found ways of making it unreadable. It was like looking at a warped mirror: you can recognize yourself, but you don't really look like that.

I struggled with the code for a few minutes, and didn't get anywhere. Anything I touched caused an error or didn't work as expected. So I stepped back and though about it, and then it dawned on me: I wasn't really reading the code. Instead, I was trying to figure out the differences between the code and what I've originally written. The problem is that this approach only works when the code is fresh in your mind. It's been seven years since the code was fresh in my mind.

Once I started reading the code as if it was all someone else's work, things fell into place. It took me less than 20 minutes to finish the integration and test it. But I still wished I could throw the old code away.

Copyright 2004 Yorai Aminov