Skip to main content

Fine-Grained Analysis of Similar Code Snippets

  • Conference paper
  • First Online:
Reuse and Software Quality (ICSR 2022)

Part of the book series: Lecture Notes in Computer Science ((LNCS,volume 13297))

Included in the following conference series:

  • 396 Accesses

Abstract

Code recommendation aims to help programmers in their coding endeavors by suggesting appropriate code snippets to complete their program. Code recommendation approaches such as code search or code repair may rely on code snippets or code templates extracted from existing projects to provide these suggestions. In this context, extracting and characterizing reusable and recurring code structures beforehand is thus essential. In this paper, we characterize recurring code structures through parametrizable code templates. Code templates can outline the common structure in code snippets along with their variation points, hence providing a convenient way to define their structural similarity. Pattern Structure is a mathematical data analysis framework for organizing objects depending on their similarity: it produces a structure supporting clustering, analysis, and knowledge discovery tasks. We propose an approach leveraging this framework and similarity defined through code templates to highlight and organize groups of similar snippets. The produced structure contains all relevant code templates as well as refinement relationships between them, and can be used to support both manual and automated analysis. We present a case study where we apply this approach to analyze snippets for the task of code sophistication, which consists of identifying and suggesting missing conditional paths in programs.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 44.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 59.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    https://docs.python.org/3/library/ast.html.

  2. 2.

    https://github.com/jgalasso/structural-template-lattice.

References

  1. Bader, J., Scott, A., Pradel, M., Chandra, S.: Getafix: learning to fix bugs automatically. Proc. ACM Program. Lang. 3(OOPSLA), 1–27 (2019)

    Google Scholar 

  2. Baxter, I.D., Yahin, A., Moura, L., Sant’Anna, M., Bier, L.: Clone detection using abstract syntax trees. In: International Conference on Software Maintenance, pp. 368–377. IEEE (1998)

    Google Scholar 

  3. Chen, T.H., Nagappan, M., Shihab, E., Hassan, A.E.: An empirical study of dormant bugs. In: 11th Working Conference on Mining Software Repositories, pp. 82–91 (2014)

    Google Scholar 

  4. Chodarev, S., Pietriková, E., Kollár, J.: Haskell clone detection using pattern comparing algorithm. In: Intnational Conference on Engineering of Modern Electric Systems, pp. 1–4. IEEE (2015)

    Google Scholar 

  5. Evans, W.S., Fraser, C.W., Ma, F.: Clone detection via structural abstraction. Software Qual. J. 17(4), 309–330 (2009)

    Article  Google Scholar 

  6. Galasso, J., Famelis, M., Sahraoui, H.A.: Code sophistication: from code recommendation to logic recommendation. CoRR abs/2201.07674 (2022)

    Google Scholar 

  7. Ganter, B., Kuznetsov, S.O.: Pattern structures and their projections. In: Delugach, H.S., Stumme, G. (eds.) ICCS-ConceptStruct 2001. LNCS (LNAI), vol. 2120, pp. 129–142. Springer, Heidelberg (2001). https://doi.org/10.1007/3-540-44583-8_10

    Chapter  MATH  Google Scholar 

  8. Godin, R., Pichet, C., Gecsei, J.: Design of a browsing interface for information retrieval. In: International Conference on Research and Development in Information Retrieval, pp. 32–39 (1989)

    Google Scholar 

  9. Hindle, A., Barr, E.T., Gabel, M., Su, Z., Devanbu, P.: On the naturalness of software. Commun. ACM 59(5), 122–131 (2016)

    Article  Google Scholar 

  10. Holmes, R., Murphy, G.C.: Using structural context to recommend source code examples. In: 27th International Conference on Software Engineering, pp. 117–125 (2005)

    Google Scholar 

  11. Jacob, F., Tairas, R.: Code template inference using language models. In: Proceedings of the 48th Annual Southeast Regional Conference, pp. 1–6 (2010)

    Google Scholar 

  12. Jiang, L., Misherghi, G., Su, Z., Glondu, S.: Deckard: scalable and accurate tree-based detection of code clones. In: International Conference on Software Engineering, pp. 96–105. IEEE (2007)

    Google Scholar 

  13. Kim, D., Nam, J., Song, J., Kim, S.: Automatic patch generation learned from human-written patches. In: International Conference on Software Engineering, pp. 802–811. IEEE (2013)

    Google Scholar 

  14. Kontogiannis, K.A., DeMori, R., Merlo, E., Galler, M., Bernstein, M.: Pattern matching for clone and concept detection. Autom. Softw. Eng. 3(1), 77–108 (1996)

    Article  MathSciNet  Google Scholar 

  15. Koschke, R., Falke, R., Frenzel, P.: Clone detection using abstract syntax suffix trees. In: 2006 13th Working Conference on Reverse Engineering, pp. 253–262. IEEE (2006)

    Google Scholar 

  16. Marchionini, G.: Exploratory search: from finding to understanding. Commun. ACM 49(4), 41–46 (2006)

    Article  Google Scholar 

  17. Merlo, E., Lavoie, T.: Computing structural types of clone syntactic blocks. In: 2009 16th Working Conference on Reverse Engineering, pp. 274–278. IEEE (2009)

    Google Scholar 

  18. Molderez, T., De Roover, C.: Search-based generalization and refinement of code templates. In: Sarro, F., Deb, K. (eds.) SSBSE 2016. LNCS, vol. 9962, pp. 192–208. Springer, Cham (2016). https://doi.org/10.1007/978-3-319-47106-8_13

    Chapter  Google Scholar 

  19. Narasimhan, K.: Clone merge-an eclipse plugin to abstract near-clone C++ methods. In: IEEE/ACM International Conference on Automated Software Engineering, pp. 819–823. IEEE (2015)

    Google Scholar 

  20. Nguyen, A.T., Nguyen, T.N.: Graph-based statistical language model for code. In: 37th International Conference on Software Engineering, vol. 1, pp. 858–868. IEEE (2015)

    Google Scholar 

  21. Nichols, L., Emre, M., Hardekopf, B.: Structural and nominal cross-language clone detection. In: International Conference on Fundamental Approaches to Software Engineering, pp. 247–263 (2019)

    Google Scholar 

  22. Raghavan, S., Rohana, R., Leon, D., Podgurski, A., Augustine, V.: Dex: a semantic-graph differencing tool for studying changes in large code bases. In: 20th International Conference on Software Maintenance, pp. 188–197. IEEE (2004)

    Google Scholar 

  23. Spadini, D., Aniche, M., Bacchelli, A.: PyDriller: Python framework for mining software repositories (2018). https://doi.org/10.1145/3236024.3264598

  24. Yang, Y., Ren, Z., Chen, X., Jiang, H.: Structural function based code clone detection using a new hybrid technique. In: Annual Computer Software and Applications Conference (COMPSAC), vol. 1, pp. 286–291. IEEE (2018)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Jessie Galasso .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2022 Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Galasso, J., Famelis, M., Sahraoui, H. (2022). Fine-Grained Analysis of Similar Code Snippets. In: Perrouin, G., Moha, N., Seriai, AD. (eds) Reuse and Software Quality. ICSR 2022. Lecture Notes in Computer Science, vol 13297. Springer, Cham. https://doi.org/10.1007/978-3-031-08129-3_1

Download citation

  • DOI: https://doi.org/10.1007/978-3-031-08129-3_1

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-031-08128-6

  • Online ISBN: 978-3-031-08129-3

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics