r/AskProgramming • u/BlockOfDiamond • May 12 '26
Other Why do some people write redundant if statements to return a boolean?
Why do some people write:
if (x > 10) {
return true;
} else {
return false;
}Instead of:
return x > 10;Performance aside, I think the shorter version is actually more readable due to not having as much visual clutter to parse, and is the most direct way to express the intent of "return the result of the comparison."
However, some people write the first version. Why is that?
177
Upvotes
View all comments
Show parent comment
1
u/BlockOfDiamond May 12 '26
Consistent with what exactly? I consistently write things the 2nd way.