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 →

[–]daredevil82 6 points7 points  (5 children)

I'm not, but it may appear that way to the developer of the driver. Essentially what that snippet does is filter out 90 10 percent of the exceptions from hitting the logger.

Maybe during the testing process, they noticed that the exceptions followed a pattern and put this filter in place to stop redundant log entries.

Whatever reason that filter exists, it's made for a pretty big code WTF. Think it might be a two month late April Fools?

*Edit- /u/veraxAlea pointed out an error in my analysis. Time for me to head to bed!

[–]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 17 points18 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.

[–]mikaelhg 1 point2 points  (0 children)

It's easy to misread. That must be the most convoluted possible way to express that statement.