website: cognitive complexity does insufficiently explain method
#7,391 opened on Jun 22, 2021
Description
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? https://github.com/rust-lang/rust-clippy/issues/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.