每当我要进行重构的时候,第一个步骤永远相同:我得为即将修改的代码建立一组可靠的测试环境
任何一个傻瓜都能写出计算机可以理解的代码。唯有写出人类容易理解的代码,才是优秀的程序员。
绝大多数情况下,函数应该放在它所使用的数据所属的object(class)内
Poorly designed code usually takes more code to do the same things, often because the code
quite literally does the same thing in several places. Thus an important aspect of improving
design is to eliminate duplicate code. The importance of this lies in future modifications to the
code. Reducing the amount of code won't make the system run any faster, because the effect on
the footprint of the programs rarely is significant. Reducing the amount of code does, however,make a big difference in modification of the code. The more code there is, the harder it is to
modify correctly. There's more code to understand. You change this bit of code here, but the
system doesn't do what you expect because you didn't change that bit over there that does much
the same thing in a slightly different context. By eliminating the duplicates, you ensure that the
code says everything once and only once, which is the essence of good design.
What is it that makes programs hard to work with? Four things I can think
of as I am typing this are as follows:
· Programs that are hard to read are hard to modify.
· Programs that have duplicated logic are hard to modify.
· Programs that require additional behavior that requires you to
change running code are hard to modify.
· Programs with complex conditional logic are hard to modify.
So, we want programs that are easy to read, that have all logic specified
in one and only one place, that do not allow changes to endanger
existing behavior, and that allow conditional logic to be expressed as
simply as possible
Replace magic number with symbolic constant
分享到:
相关推荐
NULL 博文链接:https://jianzong2000.iteye.com/blog/1668363
主要为大家分享了Map.vue基于百度地图组件重构笔记,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
[免费高清PDF]31天重构系列笔记.rar [免费高清PDF]31天重构系列笔记.rar
31天重构学习笔记中文汉化版,非常好的编程规范书籍
“每当我要进行重构的时候, 第一个步骤永远相同: 我得为即将修改的代码建立一组可靠的测试环境. 这些测试是必要的, 因为尽管遵循重构准则可以使我避免绝大多数的臭虫引入机会, 但我毕竟是人, 毕竟有可能犯错误. ...
1. 神秘命名(Mysterious Name) 2. 重复代码(Duplicated Code) 3. 过长函数(Long Function)关键在于“做什么
《重构商业:产业互联网时代的商业模式重构》读书笔记模板.pptx
根据《重构 改善既有代码结构》一书,摘录重点整理分析得出的一个PPT,希望对大家有点帮助
这个重构在微软的代码库也经常遇到。比如最经典的属性对字段的封装就是一个很好的例子,那么下面我们将看到对集合的封装,如下代码所示,调用端只需要一个集合的信息,而我们则提供了一个IList的集合,大家都知道...
重构不是一项靠着天分挥洒的艺术,而是一项工程。重构是一种有纪律的,经过训练的,有条不紊的程序整理方案,可以将整理过程中不小心引入错误的机率降到最低
重构是持续改进代码的基础。抵制重构将带来技术麻烦:忘记代码片段的功能、创建无法测试的代码等等。 而有了重构,使用单元测试、共享代码以及更可靠的无 bug 的代码这些最佳实践就显得简单多了。
重构 改善既有代码的设计笔记 网络转载,分享快乐
如何改善代码的设计-读《重构》读书笔记.pdf
关于如何重构java代码的。看过好一定很有感触。
跟着七月老师学flask第二天的笔记,详细截图说明了代码重构过程,对flask 有新的认识
第5章 重构列表5.1 重构的记录格式每个重构方法都有如下五个部分:概要(summary)简单介绍此重构方法的适用情景,以及它所做的事情。动机(motivati
重构:改善既有代码的设计(第2版)学习笔记
用例Jupytext的常见是: 在Jupyter Notebooks上进行版本控制在您喜欢的文本编辑器中编辑,合并或重构笔记本在笔记本上应用问答检查。安装您可以使用安装Jupytext pip install jupytext 或conda install jupytext -c ...