TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Can someone explain why this line exists?

25 点作者 andrewgross将近 12 年前
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 条评论

dampier将近 12 年前
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 未加载
zaroth将近 12 年前
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!"
byoung2将近 12 年前
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 未加载