Menu

Showing posts with label CodeSmell. Show all posts
Showing posts with label CodeSmell. Show all posts

Unused assignments should be removed | Sonar

Sonar code smell "Unused assignments should be removed" means, 
a dead store happens when a local variable is assigned a value that is not read by any subsequent instruction. Calculating or retrieving a value only to then overwrite it or throw it away, could indicate a serious error in the code. Even if it’s not an error, it is at best a waste of resources. Therefore all calculated values should be used.

Noncompliant Code 

i = a + b; // Noncompliant; calculation result not used before value is overwritten
i = compute();

Compliant Solution

i = a + b;
i += compute();