Possible Duplicate:
Boolean types
There are times when you want to conditionally set a bool to true or false, but otherwise just to leave it alone. But many times, you do want to set it to either true or false, based on the state of this and/or that. I’ve often wondered why, in this latter case, most people seem to write code like this (even in books):
if ((location < Platypi.Length) && (Platypi[location] != null))
{
return true;
}
else
{
return false;
}
When this would be just as clear and more concise:
return ((location < Platypi.Length) && (Platypi[location] != null));
Is being verbose really the preferred method? To me, it borders on being a code smell.
No, there is no reason to do that except to make the flow of the code explicitly clear. Personally, I would write it as:
though, because I find it just as easy to understand as the expanded version. Some people might get thrown off by it, though.
Or, it could just be a mistake people make occasionally.