Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify rule S6194 Improve rule description for coroutine cognitive complexity CPP-4992 #4533

Merged
merged 4 commits into from
Nov 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion rules/S6194/rule.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
== Why is this an issue?

Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Coroutines with high Cognitive Complexity will be difficult to maintain.
"Cognitive complexity" is a measure of how hard the control flow of a function is to understand. Code with high cognitive complexity is hard to read, understand, test, and modify.

This rule raises on coroutines with high cognitive complexity.

As a rule of thumb, high cognitive complexity is a sign that the code should be refactored into smaller, easier-to-manage pieces.

=== Which syntax in code does impact cognitive complexity score?

Here are the core concepts:

* **Cognitive complexity is incremented each time the code breaks the normal linear reading flow.** +
This concerns, for example, loop structures, conditionals, catches, switches, jumps to labels, and conditions mixing multiple operators.
* **Each nesting level increases complexity.** +
During code reading, the deeper you go through nested layers, the harder it becomes to keep the context in mind.
* **Method calls are free** +
A well-picked method name is a summary of multiple lines of code.
A reader can first explore a high-level view of what the code is performing then go deeper and deeper by looking at called functions content. +
__Note:__ This does not apply to recursive calls, those will increment cognitive score.

The method of computation is fully detailed in the pdf linked in the resources.


== Resources
Expand Down