Found via: https://twitter.com/avibryant/status/339840598871769088
Ask HN: Can someone explain why this line exists?
1–10 of 17 posts
Re: Ask HN: Can someone explain why this line exists?
#2Re: Ask HN: Can someone explain why this line exists?
#3If 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.
Re: Ask HN: Can someone explain why this line exists?
#4The 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.
Re: Ask HN: Can someone explain why this line exists?
#5If you read the code, you will notice that the FIRST time this error is encountered, it will always be logged. 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 r…
Re: Ask HN: Can someone explain why this line exists?
#6If you read the code, you will notice that the FIRST time this error is encountered, it will always be logged. 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 r…
Awesome, thanks for the explanation
Re: Ask HN: Can someone explain why this line exists?
#7Re: Ask HN: Can someone explain why this line exists?
#8If 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.
Thanks, was reviewing it with a coworker and crept up on the same conclusion. Seems a bit hard to test and definitely alarming at first glance.
Re: Ask HN: Can someone explain why this line exists?
#9Earlier quoted context omitted.
Awesome, thanks for the explanation
Thank you for an excellent counterexample for when people claim code comments are useless.
boolean alreadyLogged = !_ok;
boolean skipLogging = alreadyLogged && (Math.random() > 0.1)
if( skipLogging ) return res;Re: Ask HN: Can someone explain why this line exists?
#10Earlier quoted context omitted.
Thank you for an excellent counterexample for when people claim code comments are useless.
You could express the same thing without comments: boolean alreadyLogged = !_ok; boolean skipLogging = alreadyLogged && (Math.random() > 0.1) if( skipLogging ) return res;
if (!errorLogged || (Math.random()
But if it's a choice between comments and adding temporary variables that don't do anything, I'll almost always choose comments.