Skip to content

Instantly share code, notes, and snippets.

@DavidArno
Created July 11, 2012 11:12
Show Gist options
  • Save DavidArno/3089726 to your computer and use it in GitHub Desktop.
Save DavidArno/3089726 to your computer and use it in GitHub Desktop.
Resharper bad code advice
Take the following method:
private void UpdateCurrentBall()
{
_currentBall++;
if (_currentBall == 3)
{
_currentBall = 0;
_currentFrame++;
}
}
Resharper wants to reformat it as:
private void UpdateCurrentBall()
{
_currentBall++;
if (_currentBall != 3) return;
_currentBall = 0;
_currentFrame++;
}
Whilst this does reduce nesting, it also creates code that is more complex for the reader to understand IMO.
@jonnyreeves
Copy link

I'm torn, I agree ReSharper is pretty invasive, but if you were to add some whitespace then I think it becomes a lot clearer...

// Always increment the current value.
_currentBall++;

// We only care if the value is 3, otherwise there's nothing else going to happen.
if (_currentBall != 3) return;

// Move to the next frame
_currentBall = 0; 
_currentFrame++;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment