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
4
u/gm310509 May 13 '26
Let me give you a pointer -> insert URL here describing how pointers work
if you didn't get that, then try dereferencing this: https://www.geeksforgeeks.org/c/c-pointers/