Never fall in love with your code. Because it's crap.
posted Mar 02, 2007

Several years ago, I worked with an engineer named John Kuslak. John was a smart, smart guy. He looked like Ben Matlock.

Another engineer in the group liked to hang quotations from coworkers in his office. He had one from John near the door:

Never fall in love with your code. Because it's crap.

Another quote from John was on the opposite wall:

This sequencer is better than sex!

I included that second quote because it makes me smile. But I really want to write about the first one.

I never understood it properly until recently, when I found myself looking at some old code I'd written about 10 years ago.

That code really was crap. The most embarassing part was the comments, many of which looked like ///////////CHECK OUT THIS AWESOME GENIOUS CODE RIGHT HERE!!\\\\\\

It made me think seriously about all the code I'd written since that time. Is it all crap?

Yes. It's all crap. Even the code that seemed good at the time, even the code that still looks half-decent today. If it's not crap now, it will be when I look at it 5, 10, 20 years down the road.

Man, that is depressing. I had strong feelings for some of that code. Maybe not love, but firm affection and respect.

But you know what? My house is also crap. It was built 115 years ago, using techniques that make zero sense today.

For instance, the wall studs don't line up. When you frame a modern house, the framing needs to be very even so the drywall doesn't bulge and dip. In 1890 the framing studs could be off by a half-inch from each other, because what went on top of them wasn't drywall. It was plaster. Plaster fills in the dips and thins out for the bulges, and the wall looks perfectly flat.

Today, nobody does that - compared to drywall, plaster is crap.

It's not just the walls - there are weird holes in strange places because different heating duct systems have been installed over the years. One of those old ducts is still in use - a sheet of tin nailed to the bottoms of two floor joists in the basement. I hate looking at that duct, it looks like crap.

But I love the old house. The hardwood floors and the oak trim are beautiful. The 9-foot ceiling makes even the small rooms seem huge. Those qualities make up for the crap.

Code is like that too. A house is a complex structure and it requires maintenance and care that correspond to the style and technology that were used to build it. So with a program.

I think more time and money are spent by people to upgrade and repair existing houses than build new ones. Same deal with code.

And every time I work on my home, I try hard to do quality work even though I know it'll be crap someday. After all, I live there now.

I used to think John's quote was good advice. Now I think it's not so simple. It's true that all code becomes crap. But you have to love it when you build it or it'll be crap from the start.

Comment by Mark Wilden
posted Mar 02, 2007

When I look at my old code, it doesn't look like crap - in fact, I'm always pretty impressed.

That's depressing.

Comment by lexchou
posted Mar 02, 2007

We're growing our experiences while we're coding. everyday we are more like a master than in yesterday. I'm always impressed by my code, but months or years later, I found they are really craps, that's not depressing, I should feel happy, because I feel it's crap means I'm not crap like before.

Comment by Erik R.
posted Mar 02, 2007

This is too true. I always find myself thinking, "Man, this stuff I'm writing now is so much better than what I did last year." And I think that every single year. I'm sure this happens to all programmers.

But a lot of it has to do with changing APIs, technology, and requirements. Like I found some code the other day that was still using java.util.Vector. Gross! But that's what everyone was using back when it was written. Looking at pre-generics java code now is pretty disgusting. Just yesterday I had to go look in some javadoc to figure out what the heck the key and value types were on a Map. So it's not necessarily that the old code is crap, it's that it was the best that could be done with the tools at the time.

Comment by Swami of Salami
posted Mar 02, 2007

A good indication that you're continuing to learn and improve, avoiding the "1 year experience, duplicated 10 times" trap.

Comment by Mike G
posted Mar 02, 2007

Great post, very insightful.

Comment by Wiggins
posted Mar 02, 2007

It may seem enlightening to realize that all previous code you have written is crap, and while it is true that you will obviously grow in ability with time.

The true test for enlightenment comes when you can look back at old code you wrote 1, 5, 10 years ago, and not say, "This is crap".

Comment by
posted Mar 02, 2007

No such thing as "wall joists".

Comment by LPD
posted Mar 02, 2007

No such thing as "wall joists".

Oops. That should be "studs".

Comment by Pupeno
posted Mar 02, 2007

In every situation, love now like if it was eternal love because it is the only kind of love there exits, but tomorrow it may not be there anymore.

Comment by fudje
posted Mar 03, 2007

I look at my code for 1, 5, 10 years ago and think "This is genius!" after reading through it and pretending I'm the compiler for 30 minutes because I didn't put comments in. Which makes it crap. Sadly, this applies to code I wrote a week ago, too. I'll probably continue to not put comments in, even now.

Real annotation from a tutor @ Uni -- "This is evil. :) !!"

Comment by Remmington Johnson
posted Mar 03, 2007

I've observed the same thing with my writings. I think to myself: "This story is much, much better than that last one I wrote." Usually I look back at that story a few months later and I'm embarrassed to think it was so good.

Comment by Sanjit
posted Mar 04, 2007

They DECAY :D So no worries..heh!

Comment by red
posted Mar 05, 2007

Code rots. If it didnt, that would mean that you have learnt nothing during the time since writing the code; and that is really depressing.

Comment by Franck
posted Mar 05, 2007

Very good post. It is because we love our code that we often don't test it enough ;o)

Comment by Doug Godbey
posted Mar 05, 2007

When I was developing code for a major airline some years ago, I figured, in the beginning of my career, that what I wrote was so good, the code would live for years. After a few months of coding stuff in 370 Assembler, I realized how silly that idea was. Why? What I was writing was replacing 'crap' that was carefully crafted by a previous programmer with the same thought that I had. Nothing is pure gold for very long in this business. The solutions to the problems we work on change as do the problems themselves. I suppose it has something to do with chaos theory. Golden code fades like a bunch of flowers. Looks nice for the moment, but it will turn to 'crap' after a few days/weeks and will need to be re-crafted by a fresh pair of hands and mind.

I wish I could have known John, he sounds like a good guy to have on your team.

Comment by b
posted Apr 04, 2007

If you feel the need to write in your own code, in caps, that it is genius - you're pretty much guaranteed that it's not.

Comment by DocZayus
posted Apr 13, 2007

Old code was good then, new code looks good now.

Comment by Ben Wallis
posted Jun 14, 2007

Hey, it's not our fault!

When I was writing my old code, there wasn't enough time to write it how I really wanted to! Corporate client deadlines, ya know?

Comment by Doug
posted Nov 22, 2007

This is so very true. I've looked at code only a few weeks old and cringed at it. I'd like to think its because I'm learning new things so rapidly, though its still very disconcerting to realise something so close to home is so naff.