Hawaiʻi's Technology Community

This week, I'm deleting lots of my code.

This is actually a pretty common occurrence for me. In this case, a UI pattern that I came up with for a project works well in the small, but doesn't scale up. Other times, I've worked on a chunk of code and revisited it enough times that its structure was no longer clear, and the cognitive effort of remembering all its inconsistencies significantly outweighed the benefit of keeping it. Every once in a while I'll have thought of a better way to do something, and it's worth replacing the old code with a new implementation of existing functionality. One manager I had was increasingly perplexed with my weekly announcements of having less code. When he finally asked, I pointed out that having a small amount of the right code was much better than lots and lots of the wrong code.

I think that as developers we often have a hard time deleting code. Every line of code represents an investment in time and effort, possibly by many people. Deleting any of it can seem disrespectful. A lot of times it seems like we can just add a little bit more code--take care of some edge cases, extend the class hierarchy, add a few accessors--and the everything will be all right.

It probably won't.

I think it's unfortunate that so much effort goes into patching and extending code that really ought to have been learned from and discarded, but making that determination is tricky. If a piece of code runs well, but is ugly, are aesthetics a sufficient reason to rewrite it? Partially working code is better than nothing, maybe, and I know I can't add bugs if I don't write anything. Can we really estimate the effort to work around buggy code and accurately compare it to the cost of a rewrite?

At the very least, if I'm going to delete something, I do it wholeheartedly. I think it's better to keep the lessons rather than keeping any of the code, and I know I can always produce more code. Sometimes, though, it'd probably be better to hold off writing anything until I'm reasonably sure I'm not just going to delete it later.

Views: 217


You need to be a member of TechHui to add comments!

Join TechHui

Comment by Brian on November 23, 2012 at 11:31pm
@Paul, no less absurd than paying information workers based on hours worked.

Lazy metrics are the easiest to implement.
Comment by Alex on November 15, 2012 at 8:56am

..its that what makes programming fun though?

Being able to make something as short as possible? If you can write something in one lines that previously took 10..your day will be a better one (assuming processing efficiency is not compromised). 

Remember back in my perl and prolog days we'd spend way too much time cutting down the size of the code. Not always an effective approach, but certainly challenging.

That said, in an environment where you have to produce faster to get the job done, there will always be a lot of code you might not be very proud of...its the code you always intent to go back to a fix, but never really have the time to. Great to see that you actually do that.  

Comment by Paul Graydon on October 23, 2012 at 8:01pm

The strange thing to me is it seems like I'm still hearing from developers who are judged on a Lines Of Code basis, even though I'm yet to meet a single developer who thinks that's a good idea.  We all know it's the most absurd idea, for that matter.  Such a metric encourages just the worst ideas in programming, either making code absurdly complex or low quality, a push for new stuff with no refining of the old!


web design, web development, localization

© 2024   Created by Daniel Leuck.   Powered by

Badges  |  Report an Issue  |  Terms of Service