TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Can someone explain why this line exists?

25 pointsby andrewgrossalmost 12 years ago
https://github.com/mongodb/mongo-java-driver/blob/master/src/main/com/mongodb/ConnectionStatus.java#L213<p>Found via: https://twitter.com/avibryant/status/339840598871769088

3 comments

dampieralmost 12 years ago
If you read the code, you will notice that the FIRST time this error is encountered, it will always be logged.<p>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.<p>Finally, note that the "_ok" flag will be RESET and the resolved condition logged once the test finally returns to succeeding.
评论 #5789268 未加载
zarothalmost 12 years ago
I commented earlier, but I can't get over how ridiculous that line is. If you started by just writing the intent (!ok &#38;&#38; rand() &#62; .1) you actually have to work really hard to turn it into what you have there, and introduce a bug in the process.<p>Reminds me of this: <a href="http://www.osnews.com/story/19266/WTFs_m" rel="nofollow">http://www.osnews.com/story/19266/WTFs_m</a> - "Dude, WTF!"
byoung2almost 12 years ago
If an exception was thrown, and _ok evaluates to false, then approximately 10% of the time, log the exception to the error log. Probably just to cut down on noise in the logs, or to account for brief periods of latency where the server appears down, but isn't.
评论 #5789119 未加载