Remove Double Negative

You have a double negative conditional.

Make it a single positive conditional

 if ( !item.isNotFound() )

image/svg+xml

 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).
  • 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
  • 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.