Wednesday, April 15, 2009

Boolean is difficult

Sometimes you see the C# code like this:

if(isValid()) {
return true;
}
else {
return false;
}

or even "better":

return (isValid()? true : false);

I always wondered why not just write the code like this:

return isValid()

Is the reason is that some of the younger developers don't have any background in C, C++ or any languages where the conditional statements return int, not bool? It is psychologically difficult for them to accept Boolean as the first class citizen - data type. For them Boolean cannot be separated from the if statements or "?" operator. Am I correct? What is your opinion?

No comments: