Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>After inspecting the history of that line, my main conclusion is that there has been some incompetent programming at work.</p> <ol> <li><p>That line is gratuitously convoluted. The general form</p> <pre><code>a? true : b </code></pre> <p>for <code>boolean a, b</code> is equivalent to the simple</p> <pre><code>a || b </code></pre></li> <li><p>The surrounding negation and excessive parentheses convolute things further. Keeping in mind <a href="http://en.wikipedia.org/wiki/De_Morgan%27s_laws">De Morgan's laws</a> it is a trivial observation that this piece of code amounts to</p> <pre><code>if (!_ok &amp;&amp; Math.random() &lt;= 0.1) return res; </code></pre></li> <li><p>The commit that <a href="https://github.com/mongodb/mongo-java-driver/commit/ee7543a4f7cc26618cf78eab2a18bd33b3e101cc">originally introduced this logic</a> had</p> <pre><code>if (_ok == true) { _logger.log( Level.WARNING , "Server seen down: " + _addr, e ); } else if (Math.random() &lt; 0.1) { _logger.log( Level.WARNING , "Server seen down: " + _addr ); } </code></pre> <p>&mdash;another example of incompetent coding, but notice the <em>reversed logic</em>: here the event is logged if either <code>_ok</code> or in 10% of other cases, whereas the code in 2. <em>returns</em> 10% of the times and logs 90% of the times. So the later commit ruined not only clarity, but correctness itself. </p> <p>I think in the code you have posted we can actually see how the author intended to transform the original <code>if-then</code> somehow literally into its negation required for the early <code>return</code> condition. But then he messed up and inserted an effective "double negative" by reversing the inequality sign.</p></li> <li><p>Coding style issues aside, stochastic logging is quite a dubious practice all by itself, especially since the log entry does not document its own peculiar behavior. The intention is, obviously, reducing restatements of the same fact: that the server is currently down. The appropriate solution is to log only <em>changes</em> of the server state, and not each its observation, let alone a random selection of 10% such observations. Yes, that takes just a little bit more effort, so let's see some.</p></li> </ol> <p>I can only hope that all this evidence of incompetence, accumulated from inspecting <em>just three lines of code</em>, does not speak fairly of the project as a whole, and that this piece of work will be cleaned up ASAP.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload