6
$\begingroup$

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.

Question:

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.

$\endgroup$
  • 1
    $\begingroup$ Realizing the neural network would be the easier part of the project. The more complicated one is to create a software quality prediction model. The mentioned “McCabe's complexity” goes into the right direction, but can be extended with more features. For the beginning i would recommend to reduce the problem to simpler software problems for example in the cellular automaton domain. $\endgroup$ – Manuel Rodriguez Mar 24 at 21:32
3
$\begingroup$

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.

$\endgroup$
  • $\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 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$ – John Doucette Mar 28 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 at 1:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.