- Print
- DarkLight
Why is high cyclomatic complexity bad?
Cyclomatic complexity is a measurement developed to determine the stability and level of confidence in a program. It measures the number of linearly-independent paths through a program module.
Cognitive complexity
While having a high number of linearly-independent paths in a flow is not inherently bad, it can contribute to another measure called cognitive complexity. Essentially, cognitive complexity measures how easy it is to read a piece of code, or a flow in this case. Higher cyclomatic complexity can lead to higher cognitive complexity, which makes your flow more difficult to navigate and maintain, which can make it riskier to modify.
Unit testing
With the inclusion of unit testing in flows in the Winter '23 release, it has become best practice to create tests to validate flow functionality. If you want to test a flow with high cyclomatic complexity, there are more "paths" to test, which makes it more difficult to test all of them.
What can be done to lower cyclomatic complexity?
Break large, complicated flows into subflows
While this is not an option in certain situations (flows configured to run before save), breaking a large, complicated flow into multiple less complicated subflows can be a great way to reduce cognitive complexity because each subflow has less functionality to cover. This also allows you to create subflows for duplicated logic (if it exists in your flow).