Ooh … Begitu! I see, I see …


Setelah kelayapan di internet, cari-cari info dari sana-sini dan bongkar pasang tips (terutama programming), akhirnya baru sadar … ternyata begitu caranya … [all about tricks and tips I have found during my work as programmer.]

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()){
        } else {

or this one (in Delphi source):

        if (pnFilter.Visible = False) then
                pnFilter.Visible := True
                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:


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.


Filed under: Delphi programming, Java programming

One Response

  1. Sérgio Siegrist says:

    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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


%d bloggers like this: