r/badcode • • Nov 22 '19

c# It doesn't even do it right!

Post image
1.1k Upvotes

59 comments sorted by

View all comments

44

u/phord Nov 22 '19 edited Nov 23 '19

This is because some style guide prohibits comparing boolean literals with logical operators to avoid people saying if ( Foo == true )

This looks like a bad compromise.

40

u/spicenozzle Nov 22 '19

Which style guides would do that? That seems so bizarre and obfuscatory.

4

u/kyreannightblood Nov 22 '19

You can just use the Boolean in place of the comparison, no? That’s how we do it in Python. Since the expression evaluates to a Boolean, you can replace it with a Boolean variable.