Ned Batchelder: Deleting code


Really nice article for all you developers out there about good coding practices and specifically the issue of letting go when the time is right.

There’s plenty of information out there about how to write code. Here’s some advice on how to delete code.

The best way to delete code

This may seem obvious, but I guess it isn’t, because of the variety of other ways developers have of deleting code. Here’s how to delete code:

Select a section of code in your editor, hit the backspace key, and be done with it.

Most developers don’t like getting rid of stuff. They want to keep chunks of code around in case they need them again. They worked hard to write that chunk of code. They debugged it, it works. They don’t want to just throw it away.

These developers want to keep their old code around, and they do it by disabling it in some way: commenting it out, conditionalizing it, or just not calling it anymore.

To those developers, I say, “Use the source (control), Luke”. A source code control system (like CVS, Perforce, or Subversion), means you never have to worry that something is gone forever. CVS will have the old code if you need it again.

If you don’t have a source control system (!?!?!) or just don’t want to be bothered digging back through the revisions, then copy the chunk of code to a separate file some place, and save it away. But don’t leave it where it doesn’t belong: in your source code.

Read the rest of the article:
Ned Batchelder: Deleting code

(Via reddit)


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

sell diamonds