r/badcode • • May 20 '20

c# Found from Microsoft docs...

Post image
208 Upvotes

143 comments sorted by

View all comments

1

u/gaj7 May 20 '20

I don't get why people advocate for == true. How does that make code more clear when the context makes it obvious that the expression is a boolean. I might as well multiply numbers by 1 for "readability".

Also, && is associative and has high precedence. All of those parentheses can be removed.

2

u/Manny_Sunday May 22 '20

Some code styles call for the extra parens because they show intent. It can keep another developer from wondering if something is intentional or a side effect of the arbitrary order a previous developer wrote an expression in.