你如何以及如何重构你的代码? [英] How and How often do you refactor your code?

查看:165
本文介绍了你如何以及如何重构你的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题与这一个有关。

我正在阅读 The Pragmatic Programmer ,它强烈主张像你一样重复代码能够。然而,它没有详细说明如何做和多久。

I am reading The Pragmatic Programmer and it strongly advocates refactoring code as often as you can. However, it doesn't go into detail about how to do that and how often. How do you guys go about refactoring your code, and how often do you refactor?

推荐答案

需要什么时候和什么地方。

When and where needed.

重构本身没有意义,它是一个工具,以减轻进一步的发展。只有重构时,你会得到它的优势。一个小型的图书馆,永远不会进化和测试是完美的候选人不重构,任何时间投资在重构将不会回报。

There is no point on refactoring per se, it is a tool to ease further development. Only refactor when you will get advantage out of it. A small library that will never evolve and is tested is the perfect candidate not to refactor, any time invested on the refactoring will not pay back. Parts of your system/program that will evolve, need maintenance and are hard to read are the clear candidates to refactor.

始终考虑投资回报率(ROI),投资回报率,投资回报率,如果你开始重构你现在认为可能更好的一切,明天你将重构,也许一些时间你会得到时间实际执行一些真正的进步。

Always think on the ROI (return of investment), if you start refactoring everything that you now think could be better then tomorrow you will refactor again, and maybe some time you will get time to actually perform some real advance.

这篇关于你如何以及如何重构你的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆