重构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 ...
随机推荐
- Django创建数据表
Django中创建表. 用的django项目自带的sqlite数据库,创建完毕后将表注冊到jdango.admin,就能够在浏览器在管理了. 在django项目的models.py文件里: from ...
- sql里的in对应linq的写法 及 IQueryable转化为Dictionary
string[] arID = { "0001", "0002" }; var dict = this.service.GetMyList(m => ar ...
- 前端富文本 js 版本
https://s3.pstatp.com/pgc/v2/resource/tt_ueditor_v3_temple/tt-editor.all.js?20180425
- apache配置访问限制
1.禁止访问某些文件/目录 增加Files选项来控制,比如要不允许访问 .txt扩展名的文件,保护php类库: <Files ~ "\.txt$"> Order all ...
- jetty与tomcat
相同点: 1.tomcat与jetty都是一种servlet引擎,他们都支持标准的servlet规范和javaEE规范 不同点: 1.架构比较 jetty相比tomcat更为简单 jetty架构是基于 ...
- 为ios app添加广告条
1.广告简介 2.实现步骤: 1>.添加 iAd.framework 框架 2,使用storyboard 运行结果: 2>添加 ADBannerView 视图,并设置代理方法 3>思 ...
- Gerrit2安装配置
我主要根据下面这个文章而安装,遇到一些小问题,记录如下:2016.4.30 安装 2.12.2,要将加密的东东全装上!!!注意 1) 由于新的git-bash ...
- css content
before after demo 1 添加描述信息 div1:after{conent:"天假额外的文字"} 2 也可以显示元素的某些属性 <a class="d ...
- Mysql数据库介绍、安装和配置文件
Mysql数据库介绍.安装和配置文件 MySQL数据库介绍 mysql是开源关系型数据库,遵循GPL协议. mysql的特点是性能卓越且服务稳定,开源,无版本限制,成本低,单进程多线程,多用户,基于C ...
- HDU 5944 Fxx and string (暴力)
题意:给定一个字符串,问有多少个三元组满足 i, j, k组成一个等比数列,并且s[i] = 'y', s[j] = 'r', s[k] = 'x',且j/i ,j/k中至少一个是整数. 析:直接暴力 ...