168

My coworker insists that:
if (x == true)

Is better than:
if (x)

I'm losing my mind.
Send Help.

Comments
  • 19
    its true in some languages
  • 11
    @calmyourtities it's not true in C# ...
  • 8
    @Torbuntu please... *Whimper*
  • 19
    @calmyourtities Whenever you read a comment posted to you, do you always start off going "calm your titties? Why is this person telling me to calm my titties what the fuck?" Before realizing it's just your name? I feel liked I'd do that...
  • 15
    @ThatDude I'm adopting you as my new best friend. You have no say in the matter.

    Also! With my first account I was talking about ducks so much because of that post I had up, that my phone started auto correcting fuck to duck again... (And j swear a LOT so this was particularly astounding)
  • 4
    @Torbuntu now correct me if I'm wrong.. because I often am... But I'm pretty sure that would never compile lmfao
  • 2
  • 4
    @IDontGiveADuck people feel obligated to tell me to calm my tities (and sometimes have the nerve to tell me that tities is spelled "tittles") because they think its funny. no one has yet realized its supposed to be ironic.
  • 7
    @calmyourtities tittles? I like it. I'm using it from now on!
  • 2
    @IDontGiveADuck lol ok, you know what i meant
  • 12
    @calmyourtities still using tittles!!!
    "Hey baby, nice tittles ;)"
  • 3
    @IDontGiveADuck honestly i could see it working
  • 9
    @calmyourtities it would probably make at least a few of them laugh haha
  • 10
    @IDontGiveADuck WELL I DONT GIVE A DUCK
  • 7
    @calmyourtities good!! Keep them duckies all for yourself!!!
  • 4
    @calmyourtities what language is it better in?
  • 4
    @ThatTallNerd I just assumed he was talking about some obscure esoteric language that I don't know about or something... Like Fetlang
  • 3
    It is better if you literally have a variable named x,a better variable name would be fine for if (checkTrue)
  • 3
    @Matthewb but even if it is x, unless you're using something like python, you know that x is a Boolean anyway and with that kind of crap naming convention putting it either way won't make it more or less readable :P
  • 2
    gotta make extra sure that x dosen't identify as some other letter obviously
  • 3
    @ParkCity wat? Lol
  • 2
    @ThatDude I heard someone say duck.
  • 0
    @ThatTallNerd so far in my experience javascript and in languages where you can set a boolean to null
  • 0
    @ParkCity The alphabet is more like a spectrum anyway. Who says it has to identify as another letter? Maybe deep down x is an emoji.
  • 2
    If the majority of the code base does == true, then follow whats been previously done, no reason to change semantics.

    One arguement is that from a glance or during a code review and your on github or something in a meeting room it may be easier to read for some.

    I think what would help you a lot is if you sat down with your coworker and made a style guideline.
  • 0
    terseness beats verbosity
  • 4
    If you name your variables properly it shouldn't matter. Yeah

    if(x)

    Doesn't read well but don't name your variables as x or other unclear things. Name then something like 'canDoSomething'. Then it reads

    if(canDoSomething)

    And that makes much more sense. If the variable is a bool it's perfectly valid and reads more naturally
  • 4
    I usually stick to (x == true) for the sake of readability. I also ensure braces after if and for even if it's only one line.
  • 1
    What does he have to say about this:

    if not (x % y)
  • 2
    @IDontGiveADuck if you're writing JavaScript
    if(x) means, if x has a value and the value is not null or 0

    where as

    if(x === true) (notice the 3 ===) means if x is strictly equal to true, and not only truthy...

    But again... it's js.
    Don't hate reply ^^
  • 0
    @exceptionalGuy Living up to your name, I see. Good job!
  • 2
    @daveq you can't do it in most languages UNLESS it's a bool :) so if it's like that then it's a bool...

    Also I just used x as an example... If you didn't catch that and actually think I name my variables x I mean... :S
  • 2
    @exceptionalGuy if (x) is no less readable though... Or if (isDefault) to be more specific...

    Also, everyone should ensure braces even if it's one line... Just because you CAN skip the braces, doesn't mean you should...
  • 1
    @IDontGiveADuck I'd never think you'd do such a thing, I assumed you weren't a monster
  • 2
    @daveq rightfully so! ;)
  • 0
    You are correct and I can prove it.

    In C you can accidentally assign inside of if expressions if you forget the extra equal sign

    If(x = 1)

    Therefore prefer the
    If(x) so you can avoid an entire class of bugs 🙄

    Alternatively switch order
    If(1 == x)

    I'd ban x == 1 stlye personally if I was writing guidelines and force either inversion or removal of equals
  • 0
    @IDontGiveADuck but reading explicit code i can see what its doing calms the beast inside me to kill the programmer before me who wrote it. I personally dont know about python but in every other language if i saw "if (x)" and couldnt tell shat it was doing or for id go to jail for premeditated murder. X could be not null and that statement would be true but id have no idea what x actually was or was for
  • 1
    @Matthewb If it's written that way then there's no way it can be anything but a non-nullable Boolean... Otherwise it wouldn't compile (unless you're using Python)
  • 1
    Did you just assume a variables type?
  • 2
    because readability! KISS

    if (x != False && x == True || !(x && x || !x) && !x != True)
  • 0
    @ThatDude ducktionary
  • 0
    Actually in JavaScript this makes sense! Because Object or "1" can be truthy. But JavaScript is not a real language anyway.
  • 0
    @lun0 now those capitalized booleans hurt my eyes 😓
  • 0
    @Commodore pun intended
  • 0
    @andros705
    that is probably because c has no boolean
    so there is nor really an alternative other than really weird stuff involving negation and comparing to 0
    like if(!x == 0)
Add Comment