News for hackers. Stuff that matters.
Re:Wait, What? by mbenjaminsmith on Thursday May 30, 2013 @08:22AM (#5792023)
Looks like it's preventing most exceptions of that type from being logged. That would make sense if it's the type of exception likely to repeat itself constantly (until addressed). Using a random number as a gate is easier than measuring/throttling the rate that you're logging at.
Re:Wait, What? by m12k on Thursday May 30, 2013 @08:45AM (#5792112)
Also, if we ignore for a moment how hacky it is to implement throttling like this - why would someone write

   if(!((_ok) ? true : (Math.random() > 0.1))) 
when you could use

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

   if(!_ok && Math.random() < 0.1)

?
Re:Wait, What? by aquarion on Thursday May 30, 2013 @08:56AM (#5792158)
Because Math.random's expensive and you don't want to execute it unless you're sure.
Re:Wait, What? by drharris on Thursday May 30, 2013 @09:00AM (#5792174)
Expensive only really matters in a loop. And this logical operator would short circuit anyway.
Re:Wait, What? by masklinn on Thursday May 30, 2013 @09:18AM (#5792265)
The && operator short-circuits, if `!_ok` Math.random won't be called at all.
Re:Wait, What? by shawabawa3 on Thursday May 30, 2013 @08:43AM (#5792103)
That's the first "wait, what?". However, if you actually try and work out that horrible if statement

    !((_ok) ? true : (Math.random() > 0.1))

    _ok ? false : !(Math.random() > 0.1)

    !_ok && Math.random() <= 0.1
Seems fine...until you realise that this is the condition to exit early, it's still logging 90% of the time which is almost certainly not the desired behavior.

Not to mention _ok is a terrible name for that variable, and it's only ever being used as a negation. Why isn't it called _error or something?