Unused variables can cause risks in code

Production RiskSoftware ResiliencyCode Reliability

This code insight shows that Unused variables can cause risks in code

Counts one violation each time local variable is initialized but never used.

bad

def area(width, height):
    a = width * height
    # todo: implement logging using variable a
    return width * height

good

def area(width, height):
    return width * height

 

5362

Why you should care

A local variable in your function is not being used. This is usually caused when someone starts implementing a function but never finishes it, or someone has refactored a function but forgot to remove old parts of the function that are no longer used. Therefore you should go back and review the function to make sure it has no problems.

Business Impacts

 

Production Risk

CAST recommendations

References

https://www.quantifiedcode.com/knowledge-base/correctness/Local%20variable%20assigned%20but%20never%20used/5GJ6uvk0

5362

About CAST and Highlight’s Code Insights

Over the last 25 years, CAST has leveraged unique knowledge on software quality measurement by analyzing thousands of applications and billions of lines of code. Based on this experience and community standards on programming best practices, Highlight implements hundreds of code insights across 15+ technologies to calculate health factors of a software.

See featuresHow it works