Why Writing New Code is Better than Changing Existing Code?

Very few developers today write new ground-breaking software. Much has been written about this and I’ve found these posts to be very insightful (link1, link2).

The majority spend large amounts of their time understand existing code, and then modifying to either fix or extend it.

Now the question I’m asking myself these days is that, if the largest amount of programmers’ time is being spent in either fixing or extending code, then why is it that large complex software is never bug free or that the number of bugs never go down to a point where they can be safely ignored? Why is it that even though so much programming time is spent on fixing and extending, testing costs just seem to grow exponentially as time goes on?

My take is that the activity of fixing and extending software almost always involves modifying existing code. A bug would be fixed by adding an if statement to handle that specific error case.  A new feature can be added by adding a new case statement to a switch block. That action of modifying code increases the probability that a new fault would be introduced. In my opinion, the whole premise that in order to fix or extend functionality, existing code should be modified, is flawed.

Rather, developers should fix or extend software by adding new code. Freshly written new code is almost always better written than previous versions simply because of the fact the next developer has the benefit of hindsight.

After all when you are writing new code for a specific requirement or bug, you are definitely adding value. On the other hand, when you are changing code, you are changing value, but you’re never quite not sure whether  you are adding or subtracting value.

What we need to do these days is to acknowledge that mistakes in development are natural and normal in a development cycle, and that developers should not be penalized for them. They should be encouraged to design software that is maintainable by extension rather than modification.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: