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

website: cognitive complexity does insufficiently explain method #7391

Open
matu3ba opened this issue Jun 22, 2021 · 2 comments
Open

website: cognitive complexity does insufficiently explain method #7391

matu3ba opened this issue Jun 22, 2021 · 2 comments
Labels
A-documentation Area: Adding or improving documentation good-first-issue These issues are a good way to get started with Clippy

Comments

@matu3ba
Copy link

matu3ba commented Jun 22, 2021

What it does
Checks for methods with high cognitive complexity.

What kind of methology is used in the code is completely missing. Is this method implemented? #3793

Why is this bad
Methods of high cognitive complexity tend to be hard to both read and maintain. Also LLVM will tend to optimize small methods > better.

The first statement is unfalsifiable due to missing definition. LLVM and most compilers do graph-based optimisations, so a long switch-case is no problem for LLVM to handle. Which is in contrast to what cognitive complexity applies as method (from my experience).

Known problems
Sometimes it’s hard to find a way to reduce the complexity.
Search on GitHub

It is not possible to disable unless one annotates it in every file. Many problem domains are inherently complex and splitting the code does not make the problem easier. As it works currently, it does not take into account the code graph of the control structure in a proper way and thus is insufficient.

Example
No. You’ll see it when you get the warning.

Configuration
This lint has the following configuration variables:
cognitive-complexity-threshold: u64: The maximum cognitive complexity a function can have (defaults to 25).

Great, a configuration without understanding how they work.

@giraffate giraffate added A-documentation Area: Adding or improving documentation good-first-issue These issues are a good way to get started with Clippy labels Jun 22, 2021
@matu3ba
Copy link
Author

matu3ba commented Jun 23, 2021

The same argument holds for this description https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity

@porzechowski
Copy link

Since I'm looking for a good-first-issue, I assume that this issue is something to work with?

However I have a question, I saw that it was previously name cyclomatic complexity, and later was renamed to cognitive, but to be honest it doesn't look like it calculates either.

Briefly:
Cyclomatic tells us how many independent paths are there in a piece of code.

Cognitive tells us how hard (or easy) certain part of code is to understand, based on how much cognitive effort certain part of code requires. It will increment each time something is trying to challenge our limited cognitive capacity.

Right now this looks like a bit crippled Cyclomatic complexity.

Isn't it a bit misleading ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-documentation Area: Adding or improving documentation good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
Development

No branches or pull requests

3 participants