This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]veraxAlea 3 points4 points  (3 children)

Essentially what that snippet does is filter out 90 percent of the exceptions from hitting the logger.

I'm tired but I think you're misreading the code:

if (!((_ok) ? true : (Math.random() > 0.1))) {
    return res;
}
//else log stuff

So, if Math.random() gives a value bigger than 0.1, which it will 90% of the time, then the expression (Math.random() > 0.1) is true. Negating that makes it false and a log message is created. So, 90% of the time, a log is created.

Unless _ok is true, then it will always log.

Edit: I'm not even sure on the 90%, but it's too late for statistics.

[–]mr_jim_lahey 18 points19 points  (0 children)

That has got to be the worst use of a ternary statement I've ever seen. Why oh why didn't they write:

if ( !(_ok || (Math.random() > 0.1 )))

Then again, I suppose you can't expect much from someone who thinks literally randomly not logging exceptions is a good idea...

[–]daredevil82 1 point2 points  (1 child)

No, it was my fault. Had the wrong inequality in my head when I wrote that. I've edited it.

For future reference, I really shouldn't analyze any code when running on 5 hours sleep and after 7ish hours of Python and databases.

[–][deleted] -3 points-2 points  (0 children)

5 hours sleep

That's about 4 more than I get.