Remove Double Negative -- 移除双重否定
来源:互联网 发布:mac显示器颜色 编辑:程序博客网 时间:2024/04/30 15:15
Remove Double Negative
You have a double negative conditional.
你有一个双重否定条件语句
Make it a single positive conditional
使其变为一个肯定条件语句。
if ( !item.isNotFound() )
if ( item.isFound() )
Motivation
Double negatives are often frowned on by mavens of natural language. Often this frowning is inappropriate - certainly in English the double negative has its uses.
双重否定不太符合自然语言,不易于理解,或者容易产生错觉。(另外有时候‘!’很容易漏掉)
But that is not true in programming. There double negatives are just plain confusing. So kill them on sight.
干掉它!!!!不要让它在我面前出现第二次!
Mechanics
- If you don't have a method with the opposite sense, create one. The body can just call the original (you can fix that later).
- 如果没有相对的方法(如isNotFound的相对方法为isFound),那么就创建一个。
- Compile
- 编译
- Replace each double negative with a call to the new function
- 以肯定条件取代双重否定。
- Compile and test after each replace
- 编译测试。
- If the negative form of the method isn't used elsewhere, use Inline Method to inline it into the positive form
- 如果否定方法没有到处用到,利用InlineMethod使得变为一个肯定方法。
- If you do need both forms, consider moving the body of the negative form over to the positive and reversing its sense, and then have the negative method call the positive one.
- 如果含有两个分支,考虑将肯定条件放在第一分支,否定条件放在第二分支。
- Consider using Substitute Algorithm if the positive form is difficult to understand.
- 如果肯定条件的代码不易理解考虑使用 Substitute Algorithm(替换算法)进行重构。
- Remove Double Negative -- 移除双重否定
- 避免双重否定
- 避免双重否定
- Remove Element 移除元素
- Remove Control Flag(移除控制标记)
- 7.6 remove middle man(移除中间人)
- Remove--动态物体移除技术
- 移除Remove Microsoft Word HTML Tag
- Remove Element--原地移除重复元素
- remove移除(但不删除)
- STL移除型算法remove
- Remove Middle Man(移除中间人)
- 31天重构学习笔记26. 避免双重否定
- 双重锁定 Double-Check Locking
- Double check 双重锁检查
- Java 中的双重检查(Double-Check)
- Java 中的双重检查(Double-Check)
- Java 中的双重检查(Double-Check)
- UVA 927 - Integer Sequences from Addition of Terms
- 一直没有进步
- 游戏行业术语解决及数据计算方式
- java设计模式------工厂模式
- 杂
- Remove Double Negative -- 移除双重否定
- 如何在Quartus_II_11.0中调用ModelSim-Altera_6.5e
- 循环赛
- Mysql不能停用
- 详细解析linux进程状态
- rails中使用will_paginate针对数组进行分页处理
- Java多态之Override
- Oracle的PL/SQL语句介绍
- spring装配基本属性和集合类型