当前位置:网站首页>再读《重构》

再读《重构》

2020-11-09 10:50:00 InfoQ

{"type":"doc","content":[{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"新版本以JavaScript语言作为示例,重新思考并改进了第一版本中的众多重构手法,结合作者多年来一些新的观点和思考,带给了我们一套更为丰富完善的重构体系。"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"重构作为敏捷实践的精髓之一,在我们这个以敏捷为立身之本的公司里应当属于大家信手拈来的基本技能。虽说其基本思想长期不过时,但是第一版《重构》的发布毕竟已经是20年前的事情了,这期间软件开发行业兴起了无数新的编程思想、语言、工具、框架等,现在回过头去看第一版,会发现不仅纸质书籍难以买到,其中的一些知识上也有点脱节。新版本以JavaScript语言作为示例,重新思考并改进了第一版本中的众多重构手法,结合作者多年来一些新的观点和思考,带给了我们一套更为丰富完善的重构体系。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"通读本书,很多地方都让我产生共鸣,同时也让我对于日常的一些实践有了新的看法,并在一些问题上有了新的结论。下面想摘录一些重要的观点,并分享我的理解,与大家一起学习。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.infoq.cn\/resource\/image\/b7\/c5\/b71de8324547407486903d57382f19c5.png","alt":null,"title":null,"style":null,"href":null,"fromPaste":true,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":"center","origin":null},"content":[{"type":"text","text":"《重构》"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"重构的几个要点"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"书中讲到的几个重构要点值得每个人在实践重构的时候注意:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"重构不应改变原有程序的可观测的行为"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"把添加新功能和重构当做两件不同的事情来对待,就像两顶帽子,在开发过程中我们经常两顶帽子换着戴"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"小步重构,更安全的前进,让代码在绝大部分时间处于可工作的状态"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"捡垃圾式的重构:发现一个垃圾时,不想跑题太多,同时也不想将垃圾留在原地;如果此时很容易重构,就立即完成,否则就记录下来,等后续再来重构"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"绝大多数的重构是见机行事的,而非单独安排的一项工作"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"重构的唯一目的是让我们开发更快,用更少的工作量创造更高的价值;重构不是来自“整洁的代码”“良好的工程实践”等道德要求,而是纯粹从经济角度出发的考量"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"自测试代码是重构的基石,也是持续集成的关键环节。要想“敏捷”做到名副其实,必须要做好这三大实践–自测试代码、持续集成、重构(自测试代码和重构一起构成了TDD)"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"各种基础重构手法组合使用,以实现高级的重构目的"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}}]}

版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://www.infoq.cn/article/vFeryIBrokViqoFlrsdQ?utm_source=rss&utm_medium=article