code pal for ABAP > Documentation > Prefer IS NOT to NOT IS
Prefer IS ... NOT
to NOT ... IS
because it requires a "mental turnaround" that makes it harder to understand the negation logic.
Preferably, use a positive condition; but if the negative condition is easier to understand, change the NOT ... IS
to IS ... NOT
.
In exceptional cases, you can suppress this finding by using the pseudo comment "#EC PREFER_IS_NOT
:
IF NOT variable IS INITIAL. "#EC PREFER_IS_NOT
ENDIF.
IF NOT variable CP 'TODO*'. "#EC PREFER_IS_NOT
ENDIF.
IF NOT variable = 42. "#EC PREFER_IS_NOT
ENDIF.
Before the check:
IF NOT variable IS INITIAL.
ENDIF.
IF NOT variable CP 'TODO*'.
ENDIF.
IF NOT variable = 42.
ENDIF.
After the check:
IF variable IS NOT INITIAL.
ENDIF.
IF variable NP 'TODO*'.
ENDIF.
IF variable <> 42.
ENDIF.