[vc_row][vc_column][vc_btn title=”SOFTWARE AGILITY” style=”flat” color=”juicy-pink” link=”url:https%3A%2F%2Fdoc.casthighlight.com%2Fsoftware-resiliency%2F|||”][vc_btn title=”CODE READABILITY” style=”outline” color=”juicy-pink” link=”url:https%3A%2F%2Fdoc.casthighlight.com%2Fcategory%2Fproduct%2Findicators-methodology%2Fcode-insights%2Fsoftware-agility%2Fcode-readability%2F|||”][vc_empty_space height=”12px”][vc_row_inner][vc_column_inner][vc_column_text]
Why you should care
[/vc_column_text][vc_column_text]This pattern verifies the presence in source code of negative comparisons. Depending on the frequency, CAST Highlight will trigger this code insight.
It’s much easier to think in a positive way about a situation than to be presented with the negative alternative and having to transform it in your mind by yourself to positive. People tend to have a ‘logical’ or ‘the default behaviour’ feeling about true, which makes it easy to think about. On the contrary, false is mostly regarded is the ‘exception’, ‘the error situation’ or the ‘alternative way out’.
Expressing the logic in a positive way helps developers better and quicker understand the code and is less error-prone.
[/vc_column_text][/vc_column_inner][/vc_row_inner][vc_empty_space height=”12px”][vc_empty_space][vc_single_image image=”5362″ img_size=”full”][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text]
CAST Recommendations
Turn the negative comparison into a positive comparison whenever possible in the source code.
[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][vc_column_text color=”#dd3333″]
References
https://medium.com/@Cuadraman/why-to-stop-writting-negavite-code-af5ffb17195[/vc_column_text][/vc_column_inner][/vc_row_inner][vc_separator][vc_column_text]
How we detect
[/vc_column_text][vc_column_text]CAST Highlight counts one occurrence each time a condition contains “false” keyword or “!” character.
Example:
if ( ! (foo == value) { // +1
var = FALSE;
}
else if(foo == FALSE) { +2
var = TRUE;
}
[/vc_column_text][vc_row_inner][vc_column_inner][vc_single_image image=”5362″ img_size=”full”][vc_column_text]
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.
[/vc_column_text][vc_empty_space height=”16px”][vc_btn title=”SEE FEATURES” style=”flat” color=”black” link=”url:http%3A%2F%2Fdoc.casthighlight.com%2Foutputs-analytics%2F||target:%20_blank|”][vc_btn title=”HOW IT WORKS” style=”outline” color=”black” link=”url:http%3A%2F%2Fcasthighlight.wpengine.com%2Fhow-it-works%2F||target:%20_blank|”][/vc_column_inner][/vc_row_inner][/vc_column][/vc_row]
Leave a Reply