Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specific software metrics for Clojure programs

We are considering writing a static analyzer to collect software metrics for Clojure code. Of course it will handle the obvious stuff like number of files, functions, parameters per function, etc. I wonder if there are any metrics that are specific for Clojure code. Any ideas?

like image 400
Maurits Rijk Avatar asked Apr 13 '11 12:04

Maurits Rijk


1 Answers

On average - I think that software metrics are a dubious idea - they usually distract you from the really important question which is "how much value are we delivering to the customer??".

Having said that, I recognise they can be a necessary evil in some contexts and can occasionally give you some useful insights about your code base.

So here's a few that might be Clojure-specific.

  • Number of top-level defines (perhaps expressed as a ratio to total symbol count?)
  • Java coupling: % of symbols related to Java interop (new, ClassName., .someMethod etc.) - ideally keep coupling confined to specific modules responsible for Java interop, i.e. should be verey low % everywhere except libraries that manage the interop.
  • Average maximum nesting level of function defns (I guess 5ish good, 10+ bad??)
  • Macro density: % of forms that require macro expansion
  • % of functions with docstrings
  • % of symbols or function parameters defined with type hints
  • Average size of anonymous functions (these should probably be small!)
  • % of functions in clojure.core used (gives some idea of the "vocabulary range" and sophistication of the code)
  • (Thanks nickik!) number of ref-types created (dynamic vars, atom, ref and agent) - essential if you want to keep careful control of your mutable state!

p.s. if you get this working it would be really interesting to see the variation in results across some of the different open source clojure projects!

like image 163
mikera Avatar answered Oct 26 '22 00:10

mikera