Why should programmers never rewrite code?

Source: Internet
Author: User

Programmers have an engineer's heart, so the first thing they want to do when they get to a new venue is to push the old one back. Yes, they will never be satisfied with simple incremental labor.

Perhaps this subtle psychological orientation can explain why programmers would rather lose old code to write than tinker with when they enter a new project group. They think the old code is a mess.

But, actually, it is. The reason you think the old code is a mess is actually a basic law of programming, which is that it's easy to write code, and it's hard to read code.

Why do you think the old code is very confusing. Because it's more difficult to read code.

That's probably why code reuse hard to implement. That's how everyone in your group likes to convert the split string into an array with different functions. It's simpler and more fun to write your own functions than to guess how old functions are implemented.

As a corollary to this axiom, you can ask the programmers around them what the code is like. "It was a mess. "They will certainly say so. "I just want to push it over again. 」

Why do you think the code is so bad. "Well, look at this function, there are two pages long." Completely unaware of why these things are here. Have no idea what these APIs are all about. "They'll answer you like that.

Once, Borland's founder, Philippe Kahn, boasted to reporters that Quattro pro would be much more useful than Microsoft Excel because it was written from scratch, all new source code.

However, it is absurd to think that the new code is better than the old code. The old code is already running and tested. Countless bugs were run on the line before they were discovered, and it took the programmers a few days to fix the bugs. The fix could be a line of code or several characters, with countless hours and effort spent on these bug fixes.

When you decide to discard the old code from scratch, you also lose the results of all your predecessors ' efforts.

The new code must be better bought than the old generation. NO, overriding may pose a greater risk.

Rewriting the code for a project is also an unusually difficult decision for technology leaders. Because at the company level, reproducing code can even threaten the market competitiveness of a product. Once you've decided to rewrite the code, you're probably 2-3 years behind the competition--in the software industry, which can be long enough.

Your ideal new code will lead to improved product functionality.

But in fact, even if the new code is rewritten to implement all the functionality and requirements of the old code, the market competitiveness for the product is only marginally elevated. Because the rewriting of new technologies, new languages, the new framework does not bring a qualitative leap in the product.

Let alone in the long process of rewriting, you may encounter some unexpected situations, such as:

1, lack of money: the break of the capital chain

2, the vacancy: Core programmers leave

The end result is not good: to achieve all the original products should have all the functions and needs, wasted time and money, but also lost the market competitiveness.

So rewriting the code means that you're putting yourself in a very dangerous situation, and maybe a few years later you won't be able to write better code than before. You just spent a lot of money writing the code that already exists.

What to do when you think the old code in front of you is rotten.

You think the old code sucks, so what? They have been online and have withstood the test in real life. So when you find that your predecessor's code is at sixes and sevens, you might as well calm down and begin to understand the code and improve the code from the following three areas:

1, the structure of the code is problematic

If a network code pops up its own dialog box, the UI code needs to be processed. These problems can be solved, you have to carefully move the code, refactoring, change the interface. A careful engineer was also required to examine the changes immediately to see if there were any problems, so as not to disturb others. In fact, even larger structural changes can be done without throwing out the code.

Daniel programmer Joel Spolsky recalls that once on a project, he and his team spent months restructuring the code to move, clean, create a meaningful base class, and create the perfect interface between modules. But they were always very cautious and did not create new bugs or lose any old code.

2, the efficiency of the code is not high

Once, Netscape's rendering code was very slow to transmit. But in fact, it only affects a small part of the project, which you can optimize and even rewrite. You don't have to rewrite all the code at all. Optimize the speed of 1% work, will let you get 99% of the explosive increase.

3, the code is very ugly to write

Some of the code is really ugly, for example, Joel was involved in a project, started with an underscore to start the member variable contract, but later switched to a more standard "m_". So half the function starts with "_", and half starts with "m", which looks really ugly. But this problem can be solved in 5 minutes without having to write all the code from the beginning.

Finally, remember that writing again from scratch does not mean that you will write better code than before. Because you're not involved in the creation of the previous version, you're not really experienced at all. Once you're ready to rewrite it, you may have to make one more version of the mistake and even create more new problems.

In large business projects, it is dangerous to push back. Of course, if you're doing an experiment, think of a new algorithm that can be rewritten at any time.

If you're a job-hopping, or just took on a new project, and faced with an old code that looks pretty messy, calm down and resist the urge to rewrite, and think about these experiences.

Free to receive lamp brothers even original PHP video tutorial CD/"detail PHP" version, details of the official website customer service: http://www.lampbrother.net

"Brothers and even it education" learning PHP, Linux, HTML5, UI, Android and other video tutorials (Courseware + notes + video).

Pick up Contact QQ 2430675018

Join the event to collect the original video tutorial CD collection: http://www.lampbrother.net/newcd.html

 

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.