25 points · by andrewgross · 13y ago · 16 comments
Found via: https://twitter.com/avibryant/status/339840598871769088
The test in question is done frequently, and subsequent failures are about 100 times less interesting than the first. Unless you just like filling up disks with log files while your network is acting up.
Finally, note that the "_ok" flag will be RESET and the resolved condition logged once the test finally returns to succeeding.
boolean alreadyLogged = !_ok;
boolean skipLogging = alreadyLogged && (Math.random() > 0.1)
if( skipLogging ) return res;Reminds me of this: http://www.osnews.com/story/19266/WTFs_m - "Dude, WTF!"
Wait, what?
A ternary inside an 'if' statement, really? And even more so when one of the return values is 'true'?
Relax, it's just a bug, right? But it would be nice if programmers practiced basic Boolean reduction in their 'if' statements...
(!((_ok) ? true : (Math.random() > 0.1)))
!((_ok) ? true : (Math.random() > 0.1))
_ok ? false : !(Math.random() > 0.1)
!_ok && Math.random() <= 0.1