If you look
if (!x) { if (x == false) {
X seems to be better, but
if (!isSomething()) { if (isSomething() == false) {
You can easily watch!
What to do? Is there any recommendation?
The hidden third option is to correctly specify your variables and methods.
Instead
if (!isDisabled()) { ... }
using
if (isEnabled()) { ... }
or if you want to check the negation:
boolean disabled = !isEnabled(); if (disabled) { ... }
or add both methods:
boolean isDisabled() { return !isEnabled(); }
Edit: I found this question: Is it nice to explicitly compare with boolean constants, for example. if (b == false) in Java?
if (!isSomething()) {. , "!" , :
if (!isSomething()) {
if ( ! isSomething()) { if ( !isSomething()) {
if ( ! isSomething()) {
if ( !isSomething()) {
,
if (isSomething() == false && isSomethingElse() == false && ..),
if (isSomething() == false && isSomethingElse() == false && ..)
. "!" "not isSomething() isSomethingElse()".
, - , .
-, , if (!isSomething()):)
if (!isSomething())
, if (!x).
if (!x)
if ( !isSomething() ) {
would be the best, in my opinion. Thus, you keep the countdown symbol down, your code is readable and that !really sticks out at the beginning, so just by looking at the code, others can see its intent.
!