Understanding the use of lambda expressions in Java

Java 8 retrofitted lambda expressions, a core feature of functional programming, into a mainstream object-oriented language with an imperative paradigm. However, we do not know how Java developers have adapted to the functional style of thinking, and more importantly, what are the reasons motivating Java developers to adopt functional programming. Without such knowledge, researchers miss opportunities to improve the state of the art, tool builders use unrealistic assumptions, language designers fail to improve upon their designs, and developers are unable to explore efficient and effective use of lambdas. We present the first large-scale, quantitative and qualitative empirical study to shed light on how imperative programmers use lambda expressions as a gateway into functional thinking. Particularly, we statically scrutinize the source code of 241 open-source projects with 19,770 contributors, to study the characteristics of 100,540 lambda expressions. Moreover, we investigate the historical trends and adoption rates of lambdas in the studied projects. To get a complementary perspective, we seek the underlying reasons on why developers introduce lambda expressions, by surveying 97 developers who are introducing lambdas in their projects, using the firehouse interview method. Among others, our findings revealed an increasing trend in the adoption of lambdas in Java: in 2016, the ratio of lambdas introduced per added line of code increased by 54% compared to 2015. Lambdas were used for various reasons, including but not limited to (i) making existing code more succinct and readable, (ii) avoiding code duplication, and (iii) simulating lazy evaluation of functions. Interestingly, we found out that developers are using Java's built-in functional interfaces inefficiently, i.e., they prefer to use general functional interfaces over the specialized ones, overlooking the performance overheads that might be imposed. Furthermore, developers are not adopting techniques from functional programming, e.g., currying. Finally, we present the implications of our findings for researchers, tool builders, language designers, and developers.

[1]  A. Church A Set of Postulates for the Foundation of Logic , 1932 .

[2]  H. B. Mann Nonparametric Tests Against Trend , 1945 .

[3]  P. Sen Estimates of the Regression Coefficient Based on Kendall's Tau , 1968 .

[4]  Ralph Johnson,et al.  design patterns elements of reusable object oriented software , 2019 .

[5]  J. Hintze,et al.  Violin plots : A box plot-density trace synergism , 1998 .

[6]  Eric S. Raymond,et al.  The cathedral and the bazaar - musings on Linux and Open Source by an accidental revolutionary , 2001 .

[7]  Erik Meijer,et al.  Lambada, Haskell as a Better Java , 2000, Electron. Notes Theor. Comput. Sci..

[8]  Walter F. Tichy,et al.  A Controlled Experiment in Maintenance Comparing Design Patterns to Simpler Solutions , 2001, IEEE Trans. Software Eng..

[9]  Joshua J. Bloch Effective Java : programming language guide , 2001 .

[10]  Anton Setzer Java as a Functional Programming Language , 2002, TYPES.

[11]  Oscar Nierstrasz,et al.  Traits: Composable Units of Behaviour , 2002, ECOOP.

[12]  James M. Bieman,et al.  Design patterns and change proneness: an examination of five evolving systems , 2003, Proceedings. 5th International Workshop on Enterprise Networking and Computing in Healthcare Industry (IEEE Cat. No.03EX717).

[13]  Walter F. Tichy,et al.  A Controlled Experiment Comparing the Maintainability of Programs Designed with and without Design Patterns—A Replication in a Real Programming Environment , 2004, Empirical Software Engineering.

[14]  Radu Marinescu,et al.  Detection strategies: metrics-based rules for detecting design flaws , 2004, 20th IEEE International Conference on Software Maintenance, 2004. Proceedings..

[15]  Anthony H. Dekker Lazy functional programming in Java , 2006, SIGP.

[16]  V. Braun,et al.  Using thematic analysis in psychology , 2006 .

[17]  Shing-Chi Cheung,et al.  Do Maintainers Utilize Deployed Design Patterns Effectively? , 2007, 29th International Conference on Software Engineering (ICSE'07).

[18]  Timothy C. Lethbridge,et al.  Software Engineering Data Collection for Field Studies , 2008, Guide to Advanced Empirical Software Engineering.

[19]  Foutse Khomh,et al.  Do Design Patterns Impact Software Quality Positively? , 2008, 2008 12th European Conference on Software Maintenance and Reengineering.

[20]  Daniela E. Damian,et al.  Selecting Empirical Methods for Software Engineering Research , 2008, Guide to Advanced Empirical Software Engineering.

[21]  Andrew P. Black,et al.  How we refactor, and how we know it , 2009, 2009 IEEE 31st International Conference on Software Engineering.

[22]  Emerson R. Murphy-Hill,et al.  Java generics adoption: how new features are introduced, championed, or ignored , 2011, MSR '11.

[23]  Daniela Cruzes,et al.  Research synthesis in software engineering: A tertiary study , 2011, Inf. Softw. Technol..

[24]  Victor Pankratius,et al.  Combining functional and imperative programming for multicore software: An empirical study evaluating Scala and Java , 2012, 2012 34th International Conference on Software Engineering (ICSE).

[25]  Danny Dig,et al.  LambdaFicator: From imperative to functional programming through automated refactoring , 2013, 2013 35th International Conference on Software Engineering (ICSE).

[26]  John L. Campbell,et al.  Coding In-depth Semistructured Interviews , 2013 .

[27]  Ewan D. Tempero,et al.  What Programmers Do with Inheritance in Java , 2013, ECOOP.

[28]  Romain Robbes,et al.  Object-oriented software extensions in practice , 2013, Empirical Software Engineering.

[29]  Danny Dig,et al.  Crossing the gap from imperative to functional programming through refactoring , 2013, ESEC/FSE 2013.

[30]  Scott Oaks Java Performance - The Definitive Guide: Getting the Most Out of Your Code , 2014 .

[31]  Claes Wohlin,et al.  Towards a decision-making structure for selecting a research design in empirical software engineering , 2014, Empirical Software Engineering.

[32]  Hridesh Rajan,et al.  Mining billions of AST nodes to study actual and potential usage of Java language features , 2014, ICSE.

[33]  Viviana Bono,et al.  Trait-oriented programming in Java 8 , 2014, PPPJ '14.

[34]  Adel Noureddine,et al.  Optimising Energy Consumption of Design Patterns , 2015, 2015 IEEE/ACM 37th IEEE International Conference on Software Engineering.

[35]  Davood Mazinanian,et al.  Assessing the Refactorability of Software Clones , 2015, IEEE Transactions on Software Engineering.

[36]  Emerson R. Murphy-Hill,et al.  The Design Space of Bug Fixes and How Developers Navigate It , 2015, IEEE Transactions on Software Engineering.

[37]  Apostolos Ampatzoglou,et al.  The Effect of GoF Design Patterns on Stability: A Case Study , 2015, IEEE Transactions on Software Engineering.

[38]  Forrest Shull,et al.  Exploring Language Support for Immutability , 2016, 2016 IEEE/ACM 38th International Conference on Software Engineering (ICSE).

[39]  Stefan Hanenberg,et al.  An Empirical Study on the Impact of C++ Lambdas and Programmer Experience , 2016, 2016 IEEE/ACM 38th International Conference on Software Engineering (ICSE).

[40]  Alexander Chatzigeorgiou,et al.  Studying the evolution of PHP web applications , 2016, Inf. Softw. Technol..

[41]  Marco Tulio Valente,et al.  Why we refactor? confessions of GitHub contributors , 2016, SIGSOFT FSE.

[42]  Sarah Mount,et al.  Virtual machine warmup blows hot and cold , 2016, Proc. ACM Program. Lang..

[43]  David Lo,et al.  Empirical Study of Usage and Performance of Java Collections , 2017, ICPE.

[44]  Davood Mazinanian,et al.  Clone Refactoring with Lambda Expressions , 2017, 2017 IEEE/ACM 39th International Conference on Software Engineering (ICSE).

[45]  Lambda Expressions , 2019, Functional Interfaces in Java.