Background Context:

In the past I've heavily applied various "code quality metrics" to statically analyze code to provide an inkling of how "maintainable" it is and using things like the Maintainability Index alluded to here.

However, a problem that I face is whether a language has libraries that effectively measure such metrics - only then is it usable else it's rather subjective/arbitrary. Given the plethora of languages that one has to deal with in an enterprise system, this is can get rather unwieldy.

Proposed Idea:

Build and train an Artificial Neural Network that "ingests a folder of code" (i.e., all files within that folder/package are assumed to house the "project" whose quality metrics we'd like to compute). This may again be language dependent but let's assume it exists for a language that I'm having the hardest time with (for measuring "maintainability"): Scala.

Using numeric metrics like McCabe's complexity or Cyclomatic complexity maybe "convention" but are not entirely relevant. Few things like class/method length are almost always relevant no matter the language. Thus, providing a few "numeric metrics" + abstract notion of readability by subjective evaluation to train an ANN would be a good balance of "inputs" to the ANN. The output being either a classification of maintainability like low, medium, high etc., or a number between 0 and 1.


Has this been tried and are there any references? I spent some time digging via Google Scholar but didn't find anything "usable" or worthwhile. It's okay if it's not Scala, but have ANNs been used for measuring code quality (i.e., static analysis) and what are the benefits or disadvantages of something like this?

PS: Hopefully, the question isn't too broad, but if so, please let me know in the comments and I'll try make it as specific as possible.


1 Answer 1


There's certainly literature on a related topic: code smell detection.

A "code smell" is a sign that code has a maintenance problem, and hints at the presence of technical debt. It is reasonable to suppose that code with a lot of smells is lower quality. Code smells include things like giant classes, high cyclomatic complexity, and more.

Fontana et al. have a good 2016 survey comparing different ML methods for detecting code smells. A reverse citation search on that paper uncovers many other papers that seem relevant, including:

This seems like a pretty well-studied area. I wasn't able to find a cross-language model though, but I suspect one may well exist.

  • $\begingroup$ Code smells are quite different from maintainability as a whole. Just another dimension. At times, one may let the smell be and not impact maintainability. $\endgroup$
    – PhD
    Mar 27, 2019 at 15:17
  • $\begingroup$ @PhD That is true. Is something like this closer to what you are looking for? ieeexplore.ieee.org/abstract/document/285855 $\endgroup$ Mar 28, 2019 at 1:07
  • $\begingroup$ Interesting abstract. Will have to read up a bit to know how/what. Will keep you posted :) $\endgroup$
    – PhD
    Mar 28, 2019 at 1:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .