45

Why have you not yet approved my PR?!!?!

The PR:

```
role.filter(elem => elem !== "view" ? elem !== "use" ? elem !== "admin" ? false : true : true : true)

Comments
  • 9
    There's a reason I dislike ternaries 😒
  • 6
    Yep, that's a close on sight
  • 7
    At least add a comment 'this is a ternary comparison'

    😠
  • 6
    Tenary shouldn’t exceed one line and one check. Anything bigger than this should be good ‘ol if-statement.
  • 0
  • 1
    wut?
    like I do like me some ternary but isn't that totally unneccesary?
    simple if(a&b&c)...
  • 4
  • 2
    I like ternary operators but I also like adding sufficient parentheses that I can make sense of it the next time I look at that project
  • 3
    That's rather "septary" than "ternary" 😅
    (I don't know latin)
  • 2
    I mean, this is not too terrible but jesus fuck PARENTHESES PLEASE
  • 5
    @Jedidja

    I'd probably go with

    filter(element => ["view", "use", "admin"] .includes(element))

    Easier to read in my opinion than ternaries or a bunch of if statements.
  • 4
    @bittersweet yes...

    Using ternaries as a kind of dict filter for several values should be punished.

    One ternary, not more.

    Never nest ternaries, you're just begging to geta hell of bugs for no gain whatsoever.
  • 4
    @IntrusionCM

    Yeah and I think as soon as you're checking multiple values, it's better to chuck it into an array.

    Extensibility and all.

    There's clearly some kind of "collection" going on there, some kind of "permissibleElements" thing, where the elements seems to depend on the Role of the viewer or something like that.

    Depending on the rest of the code, maybe there should even be some kind of Map<Role, ElementArray> thing.

    That way you can request which array of elements should be displayed for which role.
  • 4
  • 5
  • 2
    (Sorry... I like to mess with bots. Some day, they will murder us all, so let me have my fun while it lasts)
  • 2
    @bittersweet as long as it isn't a brussel sprouts butt... Curry smells delicious.
  • 5
    @IntrusionCM

    You clearly have not cleaned my child's poopy diaper after curry.

    Worse than a thousand nested ternaries.
  • 1
    @bittersweet but that's not the butt, that's fecal matter.

    You're a programmer, you know that specs need to be specific... :)

    But yes, babies are tiny weapons of mass destruction. Even their excrements are useable as bio weapons.
  • 0
    Most of the time ternaries are interchangeable with the word cancer.
  • 0
    Sidenote: isn't ternary operator bit of a misleading name? In ternary logic there's three possible states as opposed to boolean logic with two. The ?: operator is really a boolean conditional operator amirite
  • 1
    @daglundberg it's called ternary operator because it has 3 operands.
  • 0
    @anux aware of that
  • 0
    @daglundberg ah. Sorry it seemed like a genuine question.
  • 0
    @anux Well in my little brain three operators is something conceptually completely different from three logical states?
  • 1
    @daglundberg that's alright. It's just that the ary-ness of operator depends on the number of operators. Unary for one operand (!a), binary for two (a+b) and so on.
  • 0
    Ternaries are shit
  • 2
    @highlight Hah. Yeah I did the same simplification before seeing you already did it. There is some other stuff that I would bug them to change too with naming. Keeping the same naming first.

    role.filter(elem => ["view", "use", "admin"].includes(elem))

    What I would ask for as a naming fix.

    roles.filter(role => ["view", "use", "admin"].includes(role))

    More since roles is a string list they could always just do roles.includes("view") when they need to know if the user has view ability.
  • 1
  • 1
    @bittersweet and I just read your comment now. That seems like the conventional way to do it to me.
  • 1
    @IntrusionCM this man clearly eats ass
  • 0
Add Comment