rubik / argon

Monitor cyclomatic complexity in Haskell programs
BSD 3-Clause "New" or "Revised" License
97 stars 8 forks source link

Provide an explanation about how cyclomatic complexity is measured #32

Closed dnadales closed 6 years ago

dnadales commented 6 years ago

Hi,

It'd be nice to have an explanation about what the different figures (1, 5, 10) actually mean. Cyclomatic complexity is usually defined for imperative programs, but I could not find what is the definition of cyclomatic complexity that argon uses. If you have a reference to a paper or article I can help with updating the readme.

rubik commented 6 years ago

Hi Damian, the code that calculates the complexity of an expression or an operator application is very straightforward: https://github.com/rubik/argon/blob/b81c34ed5185f4709204227d2528ae6c56039156/src/Argon/Visitor.hs#L53-L66

You are right that cyclomatic complexity is usually defined for imperative programs. In fact, this project was born as nothing more than an Haskell exercise for myself. It's basically a port of another project of mine, Radon, which does the same but for Python code. Radon's documentation goes a little bit more in depth, and has a couple of references: http://radon.readthedocs.io/en/latest/intro.html#cyclomatic-complexity

As you may have noticed, the project hasn't been updated in a lot of time. So if you want to step in as a maintainer, I will happily add you as collaborator.

dnadales commented 6 years ago

Thanks for replying Michele!

I've cloned you're repo last weekend, and I'm updating it to the latest stack LTS. So I might submit a pull request soon. I don't know if adding me as a mantainer will make things easier, but we could wait till I make the PR.

My intention is to use Argon inside an engine for code-climate.

Thanks for the references to the way you calculate the cyclomatic complexity. I have one question about the code above though: do you add any complexity in the case of recursion? Or what about calling other functions?

rubik commented 6 years ago

Excellent, I'll wait for the PR then.

No, recursion does not impact CC, and neither does calling other functions. This is because the original definition of McCabe states that CC is the number of possible path that the code execution can take. If one isn't using callbacks, functions don't have an impact on this.

dnadales commented 6 years ago

Thanks for the explanation Michele.

I'm trying to put the hierarchy and pipes-files into Stackage again, and then I'll submit the PR to argon, so it might take a while before the PR comes through.

rubik commented 6 years ago

Ok, there's no hurry. Yes Argon was in Stackage but then it was removed due to its dependencies.