重构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 ...
随机推荐
- Python安装Mysql驱动出错解决(最新出炉)
Python中最连接Mysql常用的驱动是 mysql-python :mysql的C语言的驱动 mysql-connector:msql官方的驱动 pymysql:python语言的驱动 我这里安装 ...
- 51NOD 1821 最优集合 栈
1821 最优集合 一个集合S的优美值定义为:最大的x,满足对于任意i∈[1,x],都存在一个S的子集S',使得S'中元素之和为i. 给定n个集合,对于每一次询问,指定一个集合S1和一个集合S2, ...
- WIN7 不用格式化磁盘怎么把FAT32系统改成NTFS系统
开始-运行,输入cmd回车.假设你要转换D盘.输入convert d: /fs:NTFS回车. [ 此时可能会提示: 访问被拒绝 因为你没有足够的特权 是权限不够的原因 开始--程序--附件 右键&q ...
- 定时邮件 已经稳定运行10天+ 从局域网linux到外网邮箱
- JDBC 详解
工作原理流程:装载驱动程序---->获得数据库连接---->使用Statement或PreparedStatement执行SQL语句----> 返回执行的结果---->关闭相关 ...
- RFC函数设置外部断点
- 编译Android VNC Server【转】
本文转载自:http://www.cnblogs.com/fengfeng/p/3289292.html 1,在如下地址checkout源代码,我checkout的版本为0.9.7http://cod ...
- Map dependencies with code maps
https://docs.microsoft.com/en-us/visualstudio/modeling/map-dependencies-across-your-solutions Instal ...
- 关于Vim的一个配置文件
昨天晚上+今天早上怒赶了一份关于Vim的自动化配置的Shell脚本,之前在github上见过一个这么一个类似的脚本项目,然后又见到同校的有一位师兄也写过这么一个类似的脚本文件,然后我也抽分跟着写一份属 ...
- HEOI2016 树
传送门 这道题还是很简单的,可以树剖,然后还有看大佬暴力模拟AC的????!! 我们就执行俩操作,一个是单点修改,这个随便修,然后就是查询一个点,离他最近的被打过标记过的祖先.这个可以这么想,我们先q ...