Using “is” for anything but singleton can increase costs
Count one violation each time one of the operand of is (or is not) is not None, True or False.
Why you should care
is
. Most prominently it is used to check whether an variable points to None
. But the operator can examine any kind of identity. This often leads to confusion because equality of two different objects will return False
.
forgiveness : As some exception can be tolerated, a few percentage of “is” for checking identity of two objects other than singleton should be allowed in the model.
Business Impacts
It is recommended to avoid these in order to ensure the code is more readable and cost effective.
CAST recommendations
References
https://www.quantifiedcode.com/knowledge-base/readability/%60not%20…%20is%60%20used%20instead%20of%20%60is%20not%60/4ORGpHyx
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.
c