Understanding the Impact of Introducing Lambda Expressions in Java Programs
DOI:
https://doi.org/10.5753/jserd.2020.744Abstract
Background: The Java programming language version eight introduced several features that encourage the functional style of programming, including the support for lambda expressions and the Stream API. Currently, there is common wisdom that refactoring legacy code to introduce lambda expressions, besides other potential benefits, simplifies the code and improves program comprehension. Aims: The purpose of this work is to investigate this belief, conducting an in-depth study to evaluate the effect of introducing lambda expressions on program comprehension. Method: We conduct this research using a mixed-method study. For the quantitative method, we quantitatively analyze 166 pairs of code snippets extracted directly either from GitHub or from recommendations from three tools (RJTL, NetBeans, and IntelliJ). We also surveyed practitioners to collect their perceptions about the benefits on program comprehension when introducing lambda expressions. We asked practitioners to evaluate and rate sets of pairs of code snippets. Results: We found contradictory results in our research. Based on the quantitative assessment, we could not find evidence that the introduction of lambda expressions improves software readability—one of the components of program comprehension. Our results suggest that the transformations recommended by the aforementioned tools decrease program comprehension when assessed by two state-of-the-art models to estimate readability. Differently, our findings of the qualitative assessment suggest that the introduction of lambda expression improves program comprehension in three scenarios: when we convert anonymous inner classes to a lambda expression, structural loops with inner conditional to a anyMatch operator, and structural loops to filter operator combined with a collect method. Implications: We argue in this paper that one can improve program comprehension when she applies particular transformations to introduce lambda expressions (e.g., replacing anonymous inner classes with lambda expressions). Also, the opinion of the participants shines the opportunities in which a transformation for introducing lambda might be advantageous. This might support the implementation of effective tools for automatic program transformations.
Downloads
References
Alqaimi, A., Thongtanunam, P., and Treude, C. (2019). Automatically generating documentation for lambda expressions in java. In Proceedings of the 16th International Conference on Mining Software Repositories, MSR ’19, pages 310–320, Piscataway, NJ, USA. IEEE Press.
Avidan, E. and Feitelson, D. G. (2017). Effects of variable names on comprehension an empirical study. In Scanniello, G., Lo, D., and Serebrenik, A., editors, Proceedings of the 25th International Conference on Program Comprehension, ICPC 2017, BuenosAires, Argentina, May 22-23, 2017, pages 55–65. IEEE Computer Society.
Baggen, R., Correia, J. P., Schill, K., and Visser, J. (2012).Standardized code quality benchmarking for improving software maintainability. Software Quality Journal, 20(2):287–307.
Buse, R. P. L. and Weimer, W. (2010). Automatically documenting program changes. In Pecheur, C., Andrews, J., and Nitto, E. D., editors, ASE2010, 25th IEEE/ACM International Conference on Automated Software Engineering, Antwerp, Belgium, September 2024, 2010, pages 33–42. ACM.
Carvalho, A., Luz, W. P., Marcilio, D., Bonifácio, R., Pinto,G., and Canedo, E. D. (2020). C3PR: A bot for fixing static analysis violations via pull requests. In Kontogiannis, K., Khomh, F., Chatzigeorgiou, A., Fokaefs, M., and Zou, M., editors,27th IEEE International Conference on software Analysis, Evolution and Reengineering, SANER2020, London, ON, Canada, February 1821, 2020, pages161–171. IEEE.
Dantas, R., Carvalho, A., Marcilio, D., Fantin, L., Silva, U.,Lucas, W., and Bonifácio, R. (2018). Reconciling the past and the present: An empirical study on the application of source code transformations to automatically rejuvenate java programs. In Oliveto, R., Penta, M. D., and shepherd, D. C., editors, 25th International Conference on Software Analysis, Evolution and Reengineering, SANER2018, Campobasso, Italy, March 2023, 2018, pages 497–501. IEEE Computer Society.
dos Santos, R. M. and Gerosa, M. A. (2018). Impacts of coding practices on readability. In Khomh, F., Roy, C. K., and Siegmund, J., editors, Proceedings of the 26th ConferenceonProgramComprehension, ICPC 2018, Gothenburg, Sweden, May 2728, 2018, pages 277–285. ACM.
Fakhoury, S., Roy, D., Hassan, S. A., and Arnaoudova, V.(2019). Improving source code readability: Theory and practice. InProceedings of the 27th International Conference on Program Comprehension, ICPC ’19, pages 2–12, Piscataway, NJ, USA. IEEE Press.
Favre, J.M., Lämmel, R., Schmorleiz, T., and Varanovich,A. (2012). 101companies: A community project on software technologies and software languages. In Furia, C. A.and Nanz, S., editors,Objects, Models, Components, Patterns, pages 58–74, Berlin, Heidelberg. Springer Berlin Heidelberg.
Godfrey, M. W. and German, D. M. (2008). The past, present, and future of software evolution. In 2008 Frontiers of Software Maintenance, pages 129–138.
Gopstein, D., Iannacone, J., Yan, Y., DeLong, L., Zhuang, Y., Yeh, M. K.C., and Cappos, J. (2017). Understanding misunderstandings in source code. In Proceedings of the 2017 11th Joint Meeting on Foundations of Software Engineering, ESEC/FSE 2017, pages 129–139, New York, NY, USA. ACM.
Gyori, A., Franklin, L., Dig, D., and Lahoda, J. (2013). Crossing the gap from imperative to functional programming through refactoring. In Proceedings of the 2013 9th Joint Meeting on Foundations of Software Engineering, ESEC/FSE 2013, pages 543–553, New York, NY, USA.ACM.
Khatchadourian, R., Tang, Y., Bagherzadeh, M., and Ahmed,S. (2019). Safe automated refactoring for intelligent parallelization of Java 8 streams. In Proceedings of the 41st International Conference on Software Engineering, ICSE’19, pages 619–630, Piscataway, NJ, USA. IEEE Press.
Landman, D., Serebrenik, A., Bouwers, E., and Vinju, J. J.(2016). Empirical analysis of the relationship between CC and SLOC in a large corpus of java methods and C functions.Journal of Software: Evolution and Process,28(7):589–618.
Lehman, M. M. and Ramil, J. F. (2001). Rules and tools for software evolution planning and management.Annals of software engineering, 11(1):15–44.
Lott, S. F. (2018).Functional Python Programming: Discover the power of functional programming, generator functions, lazy evaluation, the built-in itertools library, and monads. Packt Publishing Ltd.
Lucas, W., Bonifácio, R., Canedo, E. D., Marcilio, D., andLima, F. (2019). Does the introduction of lambda expressions improve the comprehension of java programs? Indo Carmo Machado, I., Souza, R., Maciel, R. S. P., and Santanna, C., editors, Proceedings of the XXXIII Brazilian Symposium on Software Engineering, SBES2019, Salvador, Brazil, September 2327, 2019, pages 187–196.ACM.
Mazinanian, D., Ketkar, A., Tsantalis, N., and Dig, D. (2017).Understanding the use of lambda expressions in java. Proc. ACM Program. Lang., 1(OOPSLA):85:1–85:31.
Mukaka, M. M. (2012). A guide to appropriate use of correlation coefficient in medical research.Malawi medicaljournal, 24(3):69–71.
Overbey, J. L. and Johnson, R. E. (2009). Regrowing a language: Refactoring tools allow programming languages to evolve. In Proceedings of the 24th ACM SIGPLAN Conference on Object Oriented Programming Systems Languages and Applications, OOPSLA ’09, pages 493–502, New York, NY, USA. ACM.
Parr, T. and Vinju, J. J. (2016). Towards a universal code formatted through machine learning. In van der Storm, T., Balland, E., and Varró, D., editors, Proceedings of the 2016 ACM SIGPLAN International Conference onSoftwareLanguageEngineering, Amsterdam, The Netherlands, October 31 November 1, 2016, pages 137–151. ACM.
Pennington, N. (1987). Stimulus structures and mental representations in expert comprehension of computer programs. Cognitive Psychology, 19(3):295 – 341.
Posnett, D., Hindle, A., and Devanbu, P. T. (2011). A simpler model of software readability. In van Deursen, A.,Xie, T., and Zimmermann, T., editors, Proceedings of the 8th International Working Conference on Mining Software Repositories, MSR 2011 (Colocated with ICSE), Waikiki,Honolulu, HI, USA, May 2128, 2011, Proceedings, pages 73–82. ACM.
Riaz, M., Mendes, E., and Tempero, E. (2009). A systematic review of software maintainability prediction and metrics. In 2009 3rd International Symposium on Empirical Software Engineering and Measurement, pages 367–377.
Scalabrino, S., Linares-Vásquez, M., Poshyvanyk, D., and Oliveto, R. (2016). Improving code readability modelswith textual features. In 2016 IEEE 24th International Conference on Program Comprehension (ICPC), pages 1–10.
Shrestha, N., Botta, C., Barik, T., and Parnin, C. (2020). Herewe go again: Why is it difficult for developers to learn another programming language? In Proceedings of the 42nd International Conference on Software Engineering, ICSE.
Silva, D., Tsantalis, N., and Valente, M. T. (2016). Why we refactor? confessions of github contributors. In Zimmermann, T., Cleland-Huang, J., and Su, Z., editors, Proceedings of the 24th ACM SIGSOFT International Symposium on Foundations of Software Engineering, FSE 2016, Seattle, WA, USA, November 13-18, 2016, pages 858–870.ACM.
Storey, M. D., Wong, K., and Müller, H. A. (2000). How do program understanding tools affect how programmers understand programs? Sci. Comput. Program., 36(23):183–207.
Stroustrup, B. (2013). The C++ Programming Language. Addison-Wesley Professional, 4th edition.
Tilley, S. R., Paul, S., and Smith, D. B. (1996). Towards a framework for program understanding. In WPC ’96. 4th Workshop on Program Comprehension pages 19–28.
Tsantalis, N., Mazinanian, D., and Rostami, S. (2017). Clone refactoring with lambda expressions. In 2017 IEEE/ACM 39th International Conference on Software Engineering(ICSE), pages 60–70.
Urma, R.G., Fusco, M., and Mycroft, A. (2014). Java 8 in Action: Lambdas, Streams, and functional style programming. Manning Publications Co.
von Mayrhauser, A. and Vans, A. M. (1995). Program comprehension during software maintenance and evolution.IEEE Computer, 28(8):44–55.
Wilcoxon, F. (1945). Individual comparisons by ranking methods. Biometrics Bulletin (JSTOR), 1(6):80–83.
Downloads
Published
How to Cite
Issue
Section
License
Copyright (c) 2020 Walter Lucas Monteiro Mendonça, Rodrigo Bonifácio de Almeida
This work is licensed under a Creative Commons Attribution 4.0 International License.