Ask HN: Can someone explain why this line exists?
https://github.com/mongodb/mongo-java-driver/blob/master/src/main/com/mongodb/ConnectionStatus.java#L213
Found via: https://twitter.com/avibryant/status/339840598871769088
Found via: https://twitter.com/avibryant/status/339840598871769088
16 comments
[ 6.4 ms ] story [ 23.6 ms ] threadWait, 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
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.
"Does this affect working out whether the error has been logged before?", "Does this affect whether we should log this error?", etc
EDIT: But in this case I'd still want to put a comment clarifying the "why".
Reminds me of this: http://www.osnews.com/story/19266/WTFs_m - "Dude, WTF!"