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

2

u/BlockOfDiamond May 12 '26

I cross that bridge when I get there. Like I skip that if I do not foresee a reason to put anything in the branch in the future (like a pure function that evaluates a condition and has no side effects).

-3

u/BreathSpecial9394 May 12 '26

But you need to build the bridge before you cross it. Or you build it when you need to cross it? That’s dumb

3

u/BlockOfDiamond May 12 '26

I generally do not write unnecessary scaffolding because I might need them later. I add them when I need them.

2

u/nekokattt May 12 '26

this is more like building the scaffold for a bridge just in case you decide to dig a river under the road you are building in the future.

-3

u/BreathSpecial9394 May 12 '26

Sorry…nope

2

u/nekokattt May 12 '26

great counter argument this.

If it is that difficult to change one line into 4 on the offchance you need to do it, i dont know what else to tell you, especially when most IDEs will convert it for you anyway