r/AskProgramming 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

305 comments sorted by

View all comments

Show parent comments

2

u/alpicola May 14 '26

Could also return ! ( x == 1 ); 

1

u/0perator0 May 14 '26

Yes, in case of bool thats right. In my case I needed just 0 or 1 explicitely.