simple logic of setting true or false from a boolean value
okay, I always experienced this kinda thing when I checked out other programmers’ codes in our programming projects. I must admit that we all are just ‘beginners’ in smart coding.
but I’m really tenterhook everytimes I found any code similar with these ones below. let me show you.
this one is in Java programming:
if (!pnFilter.isVisible()){
pnFilter.setVisible(true);
} else {
pnFilter.setVisible(false);
}
or this one (in Delphi source):
if (pnFilter.Visible = False) then
pnFilter.Visible := True
else
pnFilter.Visible := False;
what’s up, Doc? the programmer actually tried to set the pnFilter panel to be visible true when it wasn’t visible, and to be false when it was visible.
I always have this on my mind … why shouldn’t we use these simple one-liners instead?
the simpler code in Java version:
pnFilter.setVisible(!pnFilter.isVisible());
and in Delphi version, should be like this:
pnFilter.Visible := (not pnFilter.Visible);
any other suggestion, perhaps?
thanks for the people who have dropped by here, and I would appreciate any other input or advice. see ya.

Here is some common code that could be written in one line, in Java. The usual code is followed by the proposed one-line code.
if(x == true) y = true;
y |= x;
if(x == false) y = false;
y &= x;
if(x == true) y = false;
y &= !x;
if(x == true) y = true;
else y = false;
y = x;
if(y == true) {
if(x == true) y = true;
else y = false;
} else {
if(x == true) y = false;
else y = true;
}
y ^= !x
Sérgio Siegrist
August 27, 2008