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();
}
if (c == a || c == b || (c > a && c < b))
{
doStuff();
}
Refactor.
I found the following if statement a long long time ago.
Found this gem in my companies code today.
It is not exactly that it is wrong, strictly speaking, it's just... well, you can probably guess yourself what I would rather see here.
P.S. off the top of my head, the only reason why I would ever do something like the above, is if Java doesn't do Short-circuit evaluation (for example with the & operator).
Of course, the following example is often used, and here a conditional statement is warrented.
Of course, these are but very small issues in the grand scale of things, but it was Sherlock Holmes who said “To a great mind, nothing is little.”