Code Monkey home page Code Monkey logo

Comments (5)

rubik avatar rubik commented on May 23, 2024 1

Hi Damian,
the code that calculates the complexity of an expression or an operator application is very straightforward:

visitExp :: Exp -> Int
visitExp GHC.HsIf {} = 1
visitExp (GHC.HsMultiIf _ alts) = length alts - 1
visitExp (GHC.HsLamCase _ alts) = length (GHC.mg_alts alts) - 1
visitExp (GHC.HsCase _ alts) = length (GHC.mg_alts alts) - 1
visitExp _ = 0
visitOp :: Exp -> Int
visitOp (GHC.OpApp _ (GHC.L _ (GHC.HsVar op)) _ _) =
case getName op of
"||" -> 1
"&&" -> 1
_ -> 0
visitOp _ = 0

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.

from argon.

dnadales avatar dnadales commented on May 23, 2024

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?

from argon.

rubik avatar rubik commented on May 23, 2024

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.

from argon.

dnadales avatar dnadales commented on May 23, 2024

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.

from argon.

rubik avatar rubik commented on May 23, 2024

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

from argon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.