Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Measure code complexity in clojure

Tags:

clojure

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?

like image 860
iGEL Avatar asked Mar 08 '17 08:03

iGEL


People also ask

What is software complexity measurement?

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.

What is cyclomatic complexity in software testing?

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.

Is there more to understanding code complexity?

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.

What is the best tool to measure code complexity?

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.


1 Answers

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:

  • overuse dynamic vars
  • use def for things that should be function args
  • use setters when updaters are the correct semantic
  • wait too long before learning core.async

Interestingly, many of these mistakes might also be flagged by automatic analysis.

like image 92
Stuart Dabbs Halloway Avatar answered Oct 11 '22 07:10

Stuart Dabbs Halloway