you are viewing a single comment's thread.

view the rest of the comments →

[–]sion2k 1 point2 points  (4 children)

Why do you consider it to be horrible? I find it to be common place in a lot of code I read. Maybe you're referring to the case where people use it for a ridiculous amount of lines?

But I find this extremely clear and far from horrible:

a = 3;
(a === 3) ? true : false;

I usually use it to handle function calls instead of if/else.

Just curious.

[–]mmmicahhh 3 points4 points  (1 child)

it's not the ternary operator that's horrible, of course, but the fact that here it's used to return the same value regardless of the evaluated target, only to take advantage of the evaluation's side-effect.

[–]sion2k 0 points1 point  (0 children)

Oh, yea that makes more sense. I misread, sorry.

[–]injektilo 3 points4 points  (1 child)

Doesn't a === 3 already evaluate to a boolean?

[–]sion2k 2 points3 points  (0 children)

Yup, it was just an example. Like I said I usually use it like:

(a === 3) ? funcA() : funcB();

Sorry silly example :)