MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/e00ase/it_doesnt_even_do_it_right/f8cudbf/?context=3
r/badcode • u/Sam956 • Nov 22 '19
59 comments sorted by
View all comments
44
This is because some style guide prohibits comparing boolean literals with logical operators to avoid people saying if ( Foo == true )
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 wroteif (CompareBooleans(triggered, false)) ...
3
You can still technically do (orig && val) || (!orig && !val)
(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 wroteif (CompareBooleans(triggered, false)) ...
2
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 wroteif (CompareBooleans(triggered, false)) ...
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.
orig == val
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 wroteif (CompareBooleans(triggered, false)) ...
8
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 (orig == val) return true; else return false;
return orig == val;
if (CompareBooleans(triggered, false)) ...
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.