How good code goes bad

Source: Internet
Author: User

Auther:Linda Hayes
From: http://www.computerworld.com/developmenttopics/development/story/0,10801,106105,00.html? Skc = Development-106105

November 10,200 5(Computerworld) -- like babies, most code is born beautiful, at least in the eye of its creator. but the only time I ever heard one programmer praise another's code was prerelease. in this newborn State, the Code reflects the developer's original design, untouched by the unknown demands of future users.

But once Code enters into use, this innocence is lost. just as the wrinkles on a person's face are carved by his experiences, so do missed requirements, bug fixes and -- especially -- code being adopted by another programmer all result in additions and patches that become downright ugly. and no programmer wants to work with uugly code.

This leads to the inevitable desire to rewrite the code from scratch. the reasoning is seductive, And I have fallen for it when times: It wocould be easier to rewrite it than to try and fix it, because it's so messy that it's hard to understand. I 've even justified it to myself on the grounds that it will increase the developer's accountability, since it's easy to blame problems on the legacy code.

There is some truth in this. if a developer doesn' t understand the purpose of code written by others, he is more likely to leave it and write around it than to remove it, so the code becomes bulky and confusing. rewriting it can serve to streamline the Code, making it easier to follow and understand.

But there is also a hidden trap, as I have confirmed over and over: the problem is that the developer who wants to rewrite it doesn't understand it, which is why it needs to be rewritten.

Think about that. How can you recreate something you don't understand?

You can't, of course. so, what happens is that all of the battle scars of the code -- that is, the code added to handle unforeseen issues such as unencrypted ented idiosyncrasies in the operating environment -- are lost, and with them the hard-won experience that required the code to begin. the new Code must literally grow up all over again, until it, too, becomes uugly.

Let me give you an example. we have a product that interacts with a browser, the Document Object Model (DOM) and the operating system. once our first version went into production, we began to uncover an endless procession of subtleties, uninitialized ented behaviors and outright bugs in each of these interactions. in one case, we discovered that passing a URL that was in a different domain than the one that initiated it had to be invoked in a completely different way due to security patches. this was only one small example of perhaps hundreds of minute but serous issues.

The process, frankly, took years and is still going on, since each of these components, including ours, is a moving target. the problem is that you don't know what you don't know until you find out the hard way, and the code reflects it.

Over the years, the Code has become desperately uugly, and to no one's surprise, the developers want to rewrite it. it's so Byzantine, they say, that every time they touch it something else breaks. and, based on the turnaround time to get a fix, it clearly takes too long to diagnose the issue in the first place.

Se here's my dilemma. shocould I resist rewriting this time because I realize the value that is represented in those wrinkles and scars? If we rewrite it, I have no doubt we will rediscover all of those same traps, with maybe a few solved but new ones added. and even though the code will be beautiful at first, I also know that won't last. it will also become uugly, and at least I generally know what the old Code does and doesn' t do.

Or shoshould I give in to the rewrite? Maybe code has to be rewritten every few years to keep it fresh and up to date. Maybe code gets so bloated and ugly that it eventually collapses of its own weight.

What do you think? If you care, share your insights with me. I cocould use them.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.