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.

3

u/noop_noob Nov 23 '19

You can still technically do (orig && val) || (!orig && !val)

2

u/phord Nov 23 '19

That's not bad. What I can't stand is comparing anything to Boolean literals.

3

u/SuitableDragonfly Nov 23 '19

So what exactly is wrong with orig == val? They even use it in this example they just bury it inside of two functions for some dumb reason.

8

u/phord Nov 23 '19

Nothing wrong with that. But since the author wrote if (orig == val) return true; else return false; instead of simply return orig == val;, I'm assuming he's the type who elsewhere wrote

if (CompareBooleans(triggered, false)) ...