Tuesday, January 13, 2009

Old Code is Bad Code?

For the last six months or so, I've entertained myself far too much with Stumbleupon. I ran across this post (Never Fall in Love with Your Code, Because it's Crap). The basic premise is that what you once thought was great code, you have come to realize wasn't so great. I find this to be mostly false.

Sometimes I look back at code I wrote, and think. This is disgusting. Sometimes, I look back and think, that was brilliant. Actually, I rarely ever think my code is brilliant. I just try to make things work in a clear manner. That clear manner part sometimes gets me in trouble. I do things the hard way sometimes because I want to maintain that clean manner. And sometimes I don't. The times I don't are the times I will not look upon favorable in the future. Even if I do small, smart things within the large stupid framework I've made.

In some respects, I think I've grown dimmer. But I do have more experience and can solve *most* problems better. I think this is age. Older and slower, but more sure and reliable.

What about the other coders who read my blog? Do you think of all your old code as terrible, and the new code as great?

2 comments:

Josh Rose said...

When it comes to redundant stuff, I either reuse code, or replace it. When I replace something with something better, I obviously have looked at the old thing as inferior. When I decide to reuse code, it's typically the code that I'm more likely to be proud of.

I think I'm probably getting a better style than what I used to have, though it's probably debateable. For a while, I cared a lot more about efficiency, but I tend to go for ease of coding these days. When you have to sacrifice one or the other, which way do you lean?

Unknown said...

I feel that way less now than I used to. Once upon a time, I would revisit code from six months ago and want to change everything. Not so much any more. Also, I sometimes look at code I wrote yesterday and think "this is terrible". This is new in the last year or two.

There are two probable reasons. Reason number one is, I hope, the right one: age, just like you said. Maturity.

Reason number two is that my mix of writing and coding currently favours writing, and I may have stagnated as a programmer. January looks to be a coding month, though. I've already survived a brush with C++. So maybe I'll be all right.

Actually, that's a good example. It was terrible drudgery to port my Python/Caml prototype to C++, but the resulting code is pretty good. It's too literal of a translation, but the actual code is decent. I've been able to modify and add to it quite well.*


@Rose: I started out on the other end of efficiency vs ease of coding. Lately I have has to get my prototypes to run on bigger data sizes and efficiency has become more important. I still write a first draft without regard to efficiency, though. (eg my first draft usually uses linked lists for its core data structures, which *can't* be good for efficiency)

Um, so in answer to your question, I lean toward ease first and then rewrite for efficiency later.

*I do have an idea of how to rip out the core data structure and replace it with a flat vector, but I've restrained myself because performance has been Good Enough and the code probably wouldn't support a big rewrite well.