Why we are saying: Do not programmers to rewrite the code?

You do things that maybe do not see the results, but do not despair or anxiety, you are not do not grow, but at root.

Why we are saying: Do not programmers to rewrite the code?

Foreword

Engineers, programmers have a heart, so when they go to a new venue wanted the first thing is, all the old reinvent the wheel. Yes, they will never be satisfied with a simple incremental labor.

Perhaps this subtle psychological orientation can explain: Why programmers would rather lose to enter the old code re-write, do not want to tinker the new team, they think the old code is a mess.

But in fact this really the case? The reason why you think the old code is a mess, in fact, is determined by a fundamental law of programming, and that is: easy to write code, the code difficult to read.

Why do you think a old code in chaos? Because the code more difficult to read

This is probably the reason code Reuse difficult to achieve, can you explain why the group of Everybody loves convert the string with different functions will split into an array. Compared to guess how old function is implemented, re-write your own functions simpler and more fun.

As a corollary of this axiom, you can ask programmers around how kind they are fighting code? "It was a mess!" They'll say. "I just want to reinvent the wheel!"

Why do you think the code so badly? "Well, look at this function, yet there are two long! Do not know why these things here! Do not know these API is doing." They will answer you.

Why we are saying: Do not programmers to rewrite the code?

Once, Borland founder Philippe Kahn's original is boasted to reporters: Quattro Pro would be easy to use than Microsoft Excel much, because it is written from scratch, all new source code!

However, that the new code is better than the old code simply ridiculous. Old code has been run before, tested. Numerous bug have been run on the line before being discovered, after the discovery of programmers may spend many days just to repair these bug. This repair may be one line of code, it could be a few characters, countless time and energy spent on these bug fixes.

When you decide to abandon the old code from scratch, you also lose all the result of the efforts of his predecessor.

Two new Code must be better than the old code? NO, rewrite may pose a greater risk

对技术领导者来说,重写项目的代码也是一个异常艰难的决定。因为从公司层面说,重现代码甚至会威胁产品的市场竞争力。一旦决定重写代码,那么与竞品相比,你可能落后了2~3年——在软件行业,这时间可够长的。

三 你理想中的新代码会带来产品功能的提升

Why we are saying: Do not programmers to rewrite the code?

但事实上,即便重写的新代码可以实现旧代码的所有功能和需求,但是为产品带来的市场竞争力只有边际提升。因为重写用的新技术、新语言、新框架并没有给产品带来质的飞跃。

更不用说在重写的漫长过程中可能会遇到一些意外情况,比如:

1、缺钱:资金链的断裂

Why we are saying: Do not programmers to rewrite the code?

2、缺人:核心程序员离职

最终导致效果不佳:达不到原产品应有的所有功能和需求,白白浪费了时间和金钱,也丢掉了市场竞争力。

Why we are saying: Do not programmers to rewrite the code?

所以重写代码意味着,你在把自己置身于非常危险的境地,可能几年后你也写不出比以前更好的代码。你只是花了一大笔钱把已经存在的代码又写了一遍。

四 当你觉得眼前的旧代码很烂时,该怎么办?

你觉得旧代码写的很烂,那又怎样呢?它们已经上线,已经在实际运行中经受住了考验。所以当你发现前任留下的代码乱七八糟的时候,不妨冷静下来,从以下三个方面入手理解代码、改善代码:

1、代码的结构有问题

如果一段网络代码突然弹出了自己的对话框,应该是UI代码需要被处理。这些问题可以被解决掉,你要一次次小心地移动代码,重构,改变接口。还需要一位细心的工程师立马仔细地检查这些改变是否有问题,从而不打扰到其他人。事实上,甚至比较大的结构变化也可以不扔掉代码来完成。

大牛程序员Joel Spolsky回忆说,曾经在某个项目中,他和他的团队花了好几个月重新架构在一点上:把代码动来动去、清理、创建有意义的基类,并创建了模块之间的完美接口。但是他们始终非常小心翼翼,并没有产生新的bug,也没有丢掉任何旧代码。

2、代码的效率不高

曾经,Netscape的渲染代码被传非常缓慢。但事实上,这只会影响该项目的一小部分,这部分是你可以优化甚至重写的。你完全不必重写全部代码。优化速度的1%工作量,会让你获得99%的爆炸性提高。

3、代码写得很丑

Write some code really ugly, Joel has been involved in such a project, beginning with the start of the member variables it does underscore the agreement, but later switched to the more standard "M ." So half of the function with the " " start, half with "M" start, this looks really ugly. But this problem can be solved five minutes, all without having to write code from scratch.

Finally, you have to remember, from the beginning to write again does not mean you'll write better code than before. Because you do not have to participate on a version of creation, so you really did not have experience. Once you are ready to tear down the rewrite, you may repeat again committed a wrong version, or even create more new problems.

Five face the bad old code, Keep Calm & Carry On!

In large-scale commercial projects, to reinvent the wheel is very dangerous behavior. Of course, if you're doing an experiment, think of the new algorithm can be overridden at any time. If you just took a new project, the face looks abnormal chaos of the old code, please calm down, hold back the urge to rewrite down, think about the top voice of experience.

At last

No. I welcome everyone's attention the public opening of the new [code] as calm , the latest and most companies java face questions compiled over 1000 Road 400-page pdf document, the article will be updated on the inside, data compilation will be on the inside.

Article I remember like the point of a concern like yo, thanks for the support!

Guess you like

Origin blog.51cto.com/14570694/2470703