Answers.Body: <p>There's certainly literature on a related topic: code smell detection.</p>
  
  <p>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.</p>
  
  <p><a href="https://link.springer.com/article/10.1007/s10664-015-9378-4" rel="nofollow noreferrer">Fontana et al.</a> have a good 2016 survey comparing different ML methods for detecting code smells. A <a href="https://scholar.google.com/scholar?cites=3238500405772448084&amp;as_sdt=40005&amp;sciodt=0,10&amp;hl=en" rel="nofollow noreferrer">reverse citation search</a> on that paper uncovers many other papers that seem relevant, including:</p>
  
  <ul>
  <li>Rasool et al. 2015, <a href="https://onlinelibrary.wiley.com/doi/pdf/10.1002/smr.1737" rel="nofollow noreferrer">A review of code smell mining techniques</a></li>
  <li>da Silva Maldonado et al. 2017 <a href="https://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=7820211" rel="nofollow noreferrer">Using Natural Language Processing to Automatically Detect Self-Admitted Technical Debt</a></li>
  <li>Maneerat &amp; Muenchaisri, 2011, <a href="https://ieeexplore.ieee.org/abstract/document/5930143" rel="nofollow noreferrer">Bad-smell prediction from software design model using machine learning techniques</a></li>
  <li>Mansoor et al. 2017, <a href="https://link.springer.com/article/10.1007/s11219-016-9309-7" rel="nofollow noreferrer">Multi-objective code-smells detection using good and bad design examples</a></li>
  </ul>
  
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-27T15:17:21.250Z
Answers.Text: 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.
Answers.UserDisplayName: PhD
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-28T01:07:17.300Z
Answers.Text: @PhD That is true. Is something like this closer to what you are looking for? https://ieeexplore.ieee.org/abstract/document/285855
Answers.UserDisplayName: John Doucette
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-28T01:54:12.403Z
Answers.Text: Interesting abstract. Will have to read up a bit to know how/what. Will keep you posted :)
Answers.UserDisplayName: PhD
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-25T15:19:15.470Z
Answers.LastActivityDate: 2019-03-25T15:19:15.470Z
Answers.UserDisplayName: John Doucette
Body: <p><strong>Background Context:</strong></p>
  
  <p>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 <a href="https://quandarypeak.com/2015/02/measuring-software-maintainability/" rel="noreferrer">here</a>.</p>
  
  <p>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. </p>
  
  <p><strong>Proposed Idea:</strong></p>
  
  <p>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.</p>
  
  <p>Using numeric metrics like <code>McCabe's complexity</code> or <code>Cyclomatic complexity</code> 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 <code>low, medium, high</code> etc., or a number between <code>0 and 1</code>.</p>
  
  <p><strong>Question:</strong></p>
  
  <p>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? </p>
  
  <p><em>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.</em></p>
  
Tags: <neural-networks><machine-learning><quality-control>
Title: Are there existing examples of using neural networks for static code analysis?
UserDisplayName: PhD
ThreadText: # Are there existing examples of using neural networks for static code analysis?
  
  (Asked by: username_0 on 2019-03-24)
  
  **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](https://quandarypeak.com/2015/02/measuring-software-maintainability/).
  
  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.*
  
  **Tags:** neural-networks, machine-learning, quality-control
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-03-25. Score: 3
  
  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.](https://link.springer.com/article/10.1007/s10664-015-9378-4) have a good 2016 survey comparing different ML methods for detecting code smells. A [reverse citation search](https://scholar.google.com/scholar?cites=3238500405772448084&as_sdt=40005&sciodt=0,10&hl=en) on that paper uncovers many other papers that seem relevant, including:
  
  * Rasool et al. 2015, [A review of code smell mining techniques](https://onlinelibrary.wiley.com/doi/pdf/10.1002/smr.1737)
  * da Silva Maldonado et al. 2017 [Using Natural Language Processing to Automatically Detect Self-Admitted Technical Debt](https://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=7820211)
  * Maneerat & Muenchaisri, 2011, [Bad-smell prediction from software design model using machine learning techniques](https://ieeexplore.ieee.org/abstract/document/5930143)
  * Mansoor et al. 2017, [Multi-objective code-smells detection using good and bad design examples](https://link.springer.com/article/10.1007/s11219-016-9309-7)
  
  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.
  
  > **Comments:**
  > **username_0**: 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.  
  > **username_1**: @username_0 That is true. Is something like this closer to what you are looking for? https://ieeexplore.ieee.org/abstract/document/285855  
  > **username_0**: Interesting abstract. Will have to read up a bit to know how/what. Will keep you posted :)  
  
  ---
  
  