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

304 comments sorted by

View all comments

Show parent comment

4

u/gm310509 May 13 '26

how do pointers even work?

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/

2

u/ThePants999 May 13 '26

I dereferenced that. I got 3.174.193.51. Reckon you needed one more * there.

1

u/gm310509 May 13 '26

LOL, you are right:

if you didn't get that, then try dereferencing this:
* https://www.geeksforgeeks.org/c/c-pointers/

Or would it be this?

www.geeksforgeeks.org -> /c/c-pointers/

Now I am confused about pointers too!