In Ruby, there are several tools to calculate complexity of the code, for example the cyclomatic complexity, the ABC score or flog, as described here: http://blog.codeclimate.com/blog/2013/08/07/deciphering-ruby-code-metrics/
Are there similar tools calculate the complexity of functions and/or entire namespaces in clojure?
Measurement of software complexity based on defined algorithms provides a comprehensive assessment of the code. Regardless of the size of the code, measuring it can make your code objective, repeatable, consistent, and cost-effective. Dependable Testing – Measuring the complexity of the code tells the developer how many paths there are in the code.
In 1976, Thomas McCabe Snr proposed a metric for calculating code complexity, called Cyclomatic Complexity. It’s defined as: A quantitative measure of the number of linearly independent paths through a program’s source code…computed using the control flow graph of the program.
While there is more to understanding code complexity than I’ve covered here, we’ve gone a long way to understanding it. If this is your first time hearing about the term or learning about any of the tools, I encourage you to explore the linked articles and tools, so that you learn more.
However, a comprehensive code complexity tool, such as Codacy, does. In the screenshot above, we can see that, of the six files listed, one has a complexity of 30, a score usually considered quite high. Cyclomatic complexity is a great indicator to understand if code quality deteriorating for any given change.
To expand on my previous answer to a similar question: Homoiconicity in Clojure makes it quite easy to calculate basic code complexity measures.
That said, I wouldn't bother. The biggest sources of complexity in beginner Clojure programs come from wrong things, not structurally complex things. For example, programmers coming from a language like Ruby that encourages unstructured mutation are likely to initially:
Interestingly, many of these mistakes might also be flagged by automatic analysis.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With