Awesome, thanks for the explanation
boolean alreadyLogged = !_ok;
boolean skipLogging = alreadyLogged && (Math.random() > 0.1)
if( skipLogging ) return res; if (!errorLogged || (Math.random() < 0.1)) {
errorLogged = true;
// log error
}
But if it's a choice between comments and adding temporary variables that don't do anything, I'll almost always choose comments."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".
if( skipLogging() ) return res;