Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
We had a debate which lasted an entire afternoon in our office about this. Started from a code review being talked about on Skype and escalated into a good-natured "discussion" It seemed that everyone who walked past got involved. Some people argued with "=== true" was more readable, others that you ended up with superfluous code.
Me? Without the ===. Every time. And I'm right. -
Big-R46510y@njpugh90 I also missed if (condition != true) but no one uses that I think..
I really don't like if (true == condition) same as if (null == object)
🤐 -
lotd767110yi prefer to be as explicit as possible.
so either cast to bool or ($something === true) or ($something != false) :p -
itsdaniel0220710yIf prefer (condition) and (!condition)
Although I do make an except for String.IsNullOrWhiteSpace()
In a conditional I feel the "!" would be overlooked -
jiraTicket220510ynjpugh90: true==condition is a "yoda condition", it's terrible and should be mocked accordingly -
@Lasse @lotd That's the thing, though. Readability is subjective and very much based on what we're accustomed to. As far as I'm concerned, that completeness just looks odd and distracts me from reading the actual meaning. But I can't tell anyone else what they should find "readable".
-
afduarte59810yI think you should only use == (or === for that matter...) with languages that have truthy and falsy values. undefined and false are different in JS for example, and would both equate to falsy -
JackEdwards210yAlways if (condition), but I'll usually store the condition in a variable beforehand for readability. For example:
Instead of..
if person.height > 100
I would do something like..
let userIsTallEnough = person.height > 100
if (userIsTallEnough) -
benhongh127010yThose who write
if (condition == true)
should really write
if (((condition == true) == true) == true)
just to make it extra clear. -
watzon455610yPretty sure the if(value != true) is bad practice in JavaScript. The answer for this type of question is generally going to be language specific though as you can't do if(!value) in a language like Go

Not a rant but a question/style.
What do you prefer and why?:
if(condition)
vs
if (condition == true)
and
if (!condition)
vs
if (condition == false)
vs
if (condition != true)
undefined
style if conditions