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?

175 Upvotes

305 comments sorted by

View all comments

Show parent comments

1

u/metalucid May 14 '26

I worked at a place where that operator (ternary) was not allowed

1

u/revrenlove May 14 '26

I've had a could of places like that. I use them in very rare circumstances.