Showing posts with label if statement. Show all posts
Showing posts with label if statement. Show all posts

Wednesday, 2 May 2012

Another weird if statement

Found the following code at my work.

if (order.getOrderCode() == null) 
{
    simpleOrder = true;
}
else 
{
    if (order.getOrderCode().length() == 0) 
    {
        simpleOrder = true;
    }
}

Refactor.

Note: There are plenty of libraries that offer very good single static operations to replace the if condition, but that's not important right now.

Thursday, 29 September 2011

Weird if statement

I found the following if statement a long long time ago.

// determine if c lies between a and b
if (c == a || c == b || (c > a && c < b))
{
    doStuff();
}

Refactor.