64
akhilrb
7d

if( !condition ) vs. if(condition == false)

Pointless debate started with readability, turned into heated insults under 30 seconds πŸ˜‚

Comments
  • 6
    At least if should be fun to watch
  • 20
    if( !condition ) vs. if ( false === condition )

    I prefer the first one.
    Every developer should know about ! negation.
  • 4
    @TylerDDevRant not tripple equals.. !1 is still mostly false and !0 is mostly true.
  • 7
    If it's a single condition I use "!condition", but if multiple conditions are stacked I use "condition == false && variable = 'foo' " to get better readability
  • 8
    How barbaric! I always do if (a || false) {...}
  • 1
    !condition is "not equals true", it can be not equals to false too.
  • 5
  • 4
    @Paramite
    Looking at CSS language developer.
    Oh no! He's retarded!....
  • 3
    depends on the language. sometimes if (condition == false) is necessary if you're using a nullable type, for example in Kotlin.
  • 5
    If (String.valueOf(condition).toLowerCase.equals("false")) {
    ...
    }
  • 0
    Sadly Swift doesn’t even let you do the former. Typical babysitter language.
  • 0
    I read !isEnabled as "is not enabled". Plus when writing on a white board, I write it as NOT(isEnabled). Which in most languages translates easily (NOT -> !)
  • 2
    I don't care, just be consistent.
    I prefer the first, simply because I like less code when it doesn't impact readability and I believe negation is one of the most easily read things.
  • 0
    The second one looks way more readable to me, and it's kinda mandatory when you're dealing with non-boolean stuff
  • 1
    @Giocol like the `Boolean?` (nullable Boolean) type in Kotlin
  • 0
    p.s. devRant needs code snippet formatting
Your Job Suck?
Get a Better Job
Add Comment