Conditional expressions should not be too complex

[nz_btn text="Software Elegance" link="http://casthighlight.wpengine.com/category/product/indicators-methodology/software-elegance" target="_self" animate="false" animation_type="ghost" color="black" size="small" shape="rounded" type="normal" hover_normal="fill" hover_ghost="fill" icon="icon-dashboard"][nz_btn text="Code Complexity" target="_self" animate="false" animation_type="ghost" color="black" size="small" shape="rounded" type="ghost" hover_normal="fill" hover_ghost="screen" link="http://casthighlight.wpengine.com/category/product/indicators-methodology/software-elegance/code-complexity/" icon="icon-code"]

Why you should care

Having complex conditional expressions in your software might slow down your development team to quickly evaluate if and how the code will be run within these conditions. In addition, if conditions are misunderstood because there are too complex (especially when additional native functions like “!empty” or “!isset” makes the whole condition even more complex) , it might create unexpected behaviors during the QA phase or, more badly, in production if the logic path that verifies a condition hasn’t been followed by testers.

Business Impacts

Complex conditional operations can cause loss of time in an attempt to understand the code. It also decreases the innovation capabilities of the code. These factors can make the code unsuitable for clients.[nz_btn text="Acceleration" target="_self" animate="false" animation_type="ghost" color="orange" size="small" shape="rounded" type="normal" hover_normal="opacity" hover_ghost="fill" link="http://casthighlight.wpengine.com/category/product/indicators-methodology/acceleration/" icon="icon-office"]

CAST Recommendations

References

[nz_btn text="Style Guide" link="https://github.com/Kristories/awesome-guidelines" target="_self" icon="icon-book" animate="false" animation_type="ghost" color="turquoise" size="small" shape="rounded" type="ghost" hover_normal="fill" hover_ghost="screen"]

How we detect

This code insight verifies that source code doesn’t frequenlty contain too complex logical conditions, by looking at their number of distinct operators (mainly AND and OR). Based on specific thresholds to define whether a condition is complex or not, and depending on the frequency of occurences found in the code, Highlight counts penalty points to the scanned file.   Example of a simple conditional expression: (a && b && c && d && e && f) is not complex, because there is no distinct operators. Example of a complex conditional expression: ((a && b && c) || (d && e || f)) is complex.

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.
[nz_btn text="See features" link="http://casthighlight.wpengine.com/outputs-analytics/" target="_self" icon="icon-stats" animate="false" animation_type="ghost" color="black" size="small" shape="rounded" type="normal" hover_normal="fill" hover_ghost="fill"][nz_btn text="How it works" link="http://casthighlight.wpengine.com/how-it-works/" target="_self" icon="icon-cog" animate="false" animation_type="ghost" color="black" size="small" shape="rounded" type="ghost" hover_normal="fill" hover_ghost="fill"]
For reference only. For the complete details please refer the original article
https://doc.casthighlight.com/alt_complexconditions-the-code-contains-too-many-complex-conditions-conditionals-expressions-with-at-least-and-logical-operator-and-composed-with-too-many-simple-contitions-comparisons-expres/
Have more questions? Submit a request

Comments

Powered by Zendesk