重构26-Remove Double Negative(去掉双重否定)
尽管我在很多代码中发现了这种严重降低可读性并往往传达错误意图的坏味道,但这种重构本身还是很容易实现的。这种毁灭性的代码所基于的假设导致了错误的代码编写习惯,并最终导致bug。如下例所示:
public class Order {
public void Checkout(List<Product> products, Customer customer) {
if (!customer.getNotFlagged()) {
// the customer account is flagged
// log some errors and return
return;
}
// normal order processing
}
}
public class Customer {
public Double Balance;
public Boolean IsNotFlagged;
public Boolean getNotFlagged() {
return Balance < 30d;
}
public void setNotFlagged(Boolean notFlagged) {
IsNotFlagged = notFlagged;
}
}
public class Order {
public void Checkout(List<Product> products, Customer customer) {
if (customer.getFlagged()) {
// the customer account is flagged
// log some errors and return
return;
}
// normal order processing
}
}
public class Customer {
public Double Balance;
public Boolean IsFlagged;
public Boolean getFlagged() {
return Balance < 30d;
}
public void setFlagged(Boolean Flagged) {
IsFlagged = Flagged;
}
}
重构26-Remove Double Negative(去掉双重否定)的更多相关文章
- 重构第26天 移除双重否定(Remove Double Negative)
理解:”移除双重否定”是指把代码中的双重否定语句修改成简单的肯定语句,这样即让代码可读,同时也给维护带来了方便. 详解:避免双重否定重构本身非常容易实现,但我们却在太多的代码中见过因为双重否定降低了代 ...
- leetCode练题——26. Remove Duplicates from Sorted Array
1.题目 26. Remove Duplicates from Sorted Array--Easy Given a sorted array nums, remove the duplicates ...
- [Leetcode][Python]26: Remove Duplicates from Sorted Array
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 26: Remove Duplicates from Sorted Array ...
- LeetCode 26 Remove Duplicates from Sorted Array [Array/std::distance/std::unique] <c++>
LeetCode 26 Remove Duplicates from Sorted Array [Array/std::distance/std::unique] <c++> 给出排序好的 ...
- 26. Remove Duplicates from Sorted Array【easy】
26. Remove Duplicates from Sorted Array[easy] Given a sorted array, remove the duplicates in place s ...
- [LeetCode] Remove K Digits 去掉K位数字
Given a non-negative integer num represented as a string, remove k digits from the number so that th ...
- 26. Remove Duplicates from Sorted Array
题目: Given a sorted array, remove the duplicates in place such that each element appear only once and ...
- leetcode 26—Remove Duplicates from Sorted Array
Given a sorted array nums, remove the duplicates in-place such that each element appear only once an ...
- C# 写 LeetCode easy #26 Remove Duplicates from Sorted Array
26.Remove Duplicates from Sorted Array Given a sorted array nums, remove the duplicates in-place suc ...
随机推荐
- 5.eclipse 自带的jdk没有源码,改了它
其实JDK源码在安装的时候已经放在了jdk所在的目录下,只是eclipse使用 了不带有源码的jre,导致没找到对应的源码,点击 Window->Perference->Java-> ...
- C++ pair(对组)用法(转)
类模板:template <class T1, class T2> struct pair 参数:T1是第一个值的数据类型,T2是第二个值的数据类型. 功能:pair将一对值组合成一个值, ...
- 并不对劲的bzoj2638
为了反驳很对劲的太刀流,并不对劲的片手流决定与之针锋相对. 很对劲的太刀流-> 2638: 黑白染色 Time Limit: 20 Sec Memory Limit: 256 MBSubmit ...
- python 操作memercache类库
pip install python-memcached pip install pymemcache pip install python-libmemcached
- facebook chat api 使用
官方API文档: https://developers.facebook.com/docs/chat/ 下面是根据文档修改的类: <?php class Invite_Chat{ protect ...
- 461. Hamming Distance(汉明距离)
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- bootstrap table 分页后,重新搜索的问题
前提: 自定义搜索且有分页功能,比如搜索产品名的功能. 现象:当搜索充气娃娃的时候返回100条记录,翻到第五页. 这时候搜索按摩棒,数据有200条,结果应该是第一页的记录,但是实际显示的还是第五页的 ...
- bzoj 1612: [Usaco2008 Jan]Cow Contest奶牛的比赛【Floyd】
floyd传递关系,一个牛能确定排名的条件是能和所有牛确定关系 #include<iostream> #include<cstdio> using namespace std; ...
- 阿里云CentOS7.4启动Tomcat9没有报错,端口已经开放,但是浏览器一直等待响应解决办法7
tomcat9,启动和退出均无报错.centOS7.4防火墙已关闭,阿里云防火墙已经开放端口,telnet测试服务器的端口也通过了,**浏览器访问以后没有提示"无法访问",而是一直 ...
- springboot(六)自动配置原理和@Conditional
官方参考的配置属性:https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#common-appl ...