重构 笔记

每当我要进行重构的时候,第一个步骤永远相同:我得为即将修改的代码建立一组可靠的测试环境

 

任何一个傻瓜都能写出计算机可以理解的代码。唯有写出人类容易理解的代码,才是优秀的程序员。

 

绝大多数情况下,函数应该放在它所使用的数据所属的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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值