2
aab13
7y

A piece of my soul dies when I see code like this:
Y = x ? false : true
I was already mad because the file that contained this line was written in a way that makes it really hard to fix any bugs or add feature that were supposed to be already implemented, then the sight of this just made me feel sad

Comments
  • 0
    Depending on the language it is useful. What if x is a truelike value like 1, "hello", {} in JS. But you need a boolean value to work with.
  • 2
    Personally I don't mind this style of coding.

    In python, I go crazy with syntactic sugar 😀
  • 1
    @Codex404 that was my first thought, but when i checked, x takes true or false
  • 0
    @coolq one of my pet peeves in code is useless selections. That's why this makes me sad
  • 0
    @Codex404 You can just use the 'not' operator: !x
  • 0
    @novopl ah, yes I thought it said x? true:false;

    And I know you can use !!x for that but people may get confused by it.
  • 0
    @Codex404 then "x != 0" would be much cleaner
  • 1
    @Embeddeded but it could be a string or something else as well and y=(x != 0) doesnt make it more clear.
  • 1
    @Codex404 So, a type that could be "Null" or "None"?

    1.:
    isValid = someObject ? true : false;

    2.:
    isValid = someObject != null

    3.:
    isValid = someObject != null ? true : false

    4.:
    isValid = !!someObject

    I'd still vote for 2!
  • 1
    @Embeddeded i prefer 1 or 4, or maybe 2 with brackets.
Add Comment