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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
References
Bader, J., Scott, A., Pradel, M., Chandra, S.: Getafix: learning to fix bugs automatically. Proc. ACM Program. Lang. 3(OOPSLA), 1–27 (2019)
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)
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)
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)
Evans, W.S., Fraser, C.W., Ma, F.: Clone detection via structural abstraction. Software Qual. J. 17(4), 309–330 (2009)
Galasso, J., Famelis, M., Sahraoui, H.A.: Code sophistication: from code recommendation to logic recommendation. CoRR abs/2201.07674 (2022)
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
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)
Hindle, A., Barr, E.T., Gabel, M., Su, Z., Devanbu, P.: On the naturalness of software. Commun. ACM 59(5), 122–131 (2016)
Holmes, R., Murphy, G.C.: Using structural context to recommend source code examples. In: 27th International Conference on Software Engineering, pp. 117–125 (2005)
Jacob, F., Tairas, R.: Code template inference using language models. In: Proceedings of the 48th Annual Southeast Regional Conference, pp. 1–6 (2010)
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)
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)
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)
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)
Marchionini, G.: Exploratory search: from finding to understanding. Commun. ACM 49(4), 41–46 (2006)
Merlo, E., Lavoie, T.: Computing structural types of clone syntactic blocks. In: 2009 16th Working Conference on Reverse Engineering, pp. 274–278. IEEE (2009)
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
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)
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)
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)
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)
Spadini, D., Aniche, M., Bacchelli, A.: PyDriller: Python framework for mining software repositories (2018). https://doi.org/10.1145/3236024.3264598
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)
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2022 Springer Nature Switzerland AG
About this paper
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)