Bad variable names can increase costs
This code insight counts one violation each time the name do not complies with: Constants (([A-Z_][A-Z0-9_]*)|(__.*__))- underscore allowed
- upercase
- anything delimited with double underscore
- underscore allowed
- lowercase
Examples
PI = 3.14 # (constant because assigned only one time in root scope) CONST1 = [item1, item2] # (constant because initialized with a literal list CONST2 = "this is a string" # (constant because initialized with a literal string my_var = 10 # (variable because assigned later in same scope)
class toto:
def meth() :
CONST3 = 100 # (constant because assigned only one time in meth() scope)
var = 10 # (variable because assigned later)
print 'yo'
var = 5
my_var2 = var # (variable because not initialized with a literal
PI=5 # (variable because assigned two times in "meth()" scope)
print(PI)
PI = PI_0
my_var = 5
Why you should care
The name of the variable or constant does match the naming convention. This error is a stylistic warning. The code will execute. But you can improve the readability of the code by renaming the variable or constant to match the following regular expression:
- Variables:
[a-z_][a-z0-9_]$ - Constants:
(([A-Z_][A-Z0-9_]*)|(__.*__))$
Business Impacts
[nz_btn text="Cost" target="_self" animate="false" animation_type="ghost" color="green" size="small" shape="rounded" type="normal" hover_normal="opacity" hover_ghost="fill" link="http://casthighlight.wpengine.com/category/product/indicators-methodology/innovation/" icon="icon-office"]CAST recommendations
References
https://www.quantifiedcode.com/knowledge-base/maintainability/Avoid%20using%20%22non-Pythonic%22%20variable%20names/4m6i5DpzAbout 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.
For reference only. For the complete details please refer the original article
https://doc.casthighlight.com/alt_badnaming-avoid-bad-variable-name/
https://doc.casthighlight.com/alt_badnaming-avoid-bad-variable-name/
Comments