We Don't Like to Back Up

Feb 20

We Don't Like to Back Up

One of the problems in writing good code is a reluctance to back up. An example —

I was writing a little app for a client the other day, and I had a written some PHP to split an unordered list (UL) into three columns. Then I needed this code on another page…so I cut-and-pasted it in. Then I needed it in another page…so I did that again.

And this is how it happens — you start cut-and-pasting code all over the place, DRY be damned.

Why do we do this? I think I figured out why today: we don’t like to back up.

For me to do things right and fix my code, I would have had to cease forward progress and back up a step. I would have needed to figure out a way to encapsulate that code, put it somewhere where other code could get at it, change my existing references to call the new code, and debug the results.

And we don’t like to do this. We don’t like to abandon forward progress even if the end result is better.

I don’t have an answer for this, really, but writing it at least helps put it in perspective.


Comments

by Azeroth,   February 21, 2009 2:08 AM  

I think it's a matter of discipline. But what the hell, I'm guilty of the same thing. Eeehaw!


by Eric,   February 21, 2009 3:52 PM  

The third time's the charm. That's my rule, anyway.

The second time you reuse something, it's just quicker to cut and paste. But the third time? Odds are good if code is that popular, you're not going to use it just three times. :) The third time calls for making the code reusable, in my experience.


by Chris_,   February 21, 2009 6:52 PM  

I'm going to have to go with Eric on this. The first time I write something, I always stop to think about how I might reuse it. The second time I write it I start to make the code more dynamic by replacing values with variables, etc. The third time I write it I try to make it completely it's own beast.

I think it just comes with how many lines of code you end up writing daily...if you're pounding the keys day after day, you find yourself constantly trying to think about how to save yourself (and others) time the next time around.

If you're spending a majority of your day coming up with new ideas and thinking through the bigger picture of things, copy/paste is really all you need to get the job done on the small stuff!



Comments are Closed

Thanks to all who participated.

Want to advertise on this site? Contact FM.