Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Opposite Operator #30

Open
FMCalisto opened this issue Mar 1, 2016 · 0 comments
Open

Opposite Operator #30

FMCalisto opened this issue Mar 1, 2016 · 0 comments

Comments

@FMCalisto
Copy link

Use opposite operator instead of the logic complement operator.

376         }
377         // If not, then display error dialog
378         else {
379             final boolean exit = !(errorCode == WebViewClient.ERROR_HOST_LOOKUP);
380             me.runOnUiThread(new Runnable() {
381                 public void run() {

Why is this an issue?

Use opposite operator instead of negating the whole expression with a logic complement operator. It makes code easier to read and understand.

Ex:

public boolean bar(int a, int b) {

  if (!(a == b)) { // use !=
    return false;
  }

  if (!(a < b)) { // use >=
    return false;
  }

  return true;
}

Source

Related code pattern

Enforces opposite operator instead of negating

Enforces the usage of the opposite operator instead of negating the whole expression with a logic complement operator.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant