Principles of Refactoring--------reading Refactoring chapter 2

类别:软件工程 点击:0 评论:0 推荐:
Refactoring:
     A change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior.
事不过三:
  The first time you do something,just do it,The second time you do something simular,you wince at the duplication,but you do the duplicate thing anyway. The third time you do somthing similar,you refactor.                ----------Don Roberts
Remember:
  Code has to work mostly correctly before you refactor!
第二章主要介绍了
1,为什么使用Refactor
2,什么时候需要Refactor
3,Refactor可能带来的问题

下边让我来逐一介绍:(其实也没有什么好介绍的,大体知道就行了,他所说明的东西我们想想一般都觉得是正确的,呵呵,还是让我来理一下思路)
(Refactoring的主要目的是让代码readable and easy to modify,Refactoring modifies the existing code in such a way that it doesn't affect the observable behavior.

1,Why should you refactor?
  a.  improves the Design of software
  b.  make software easier to understand
  c.  helps you find bugs(as Refactor tear your code into parts)
  d.  help you program faster(in the long run)

2,  When should you refactor?
a. when you add function
b. when you need to fix a bug
c. as you do a code review

3,Problems with refactoring
a. Databases(这里作者讲的我不是很明白,可能是我对数据库设计的实践比较少吧)
b. Changing interfaces (especially when the published interfaces)

最后让这一章以Refactoring和Design的关系来结束:
最好的Process是:
    Design first,但是不一定要把考虑到的所有未来变化的编码全部放到你的设计中来,前提是你能保证这种变化对于refactor来说是可以比较简单的解决的,从而我们可以看出Refactor和Design是相辅相成的,只不过design为主,refactor为辅,refactor使我们可以进行simple design at first,but end up with good-designed code!~



    Ok,finish here!!



本文地址:http://com.8s8s.com/it/it32851.htm