skip to main content
research-article
Open Access
Artifacts Evaluated & Functional

Understanding the use of lambda expressions in Java

Published:12 October 2017Publication History
Skip Abstract Section

Abstract

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.

References

  1. Theodoros Amanatidis and Alexander Chatzigeorgiou. 2016. Studying the evolution of PHP web applications. Information and Software Technology 72 (2016), 48 – 67. DOI: Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. A. Ampatzoglou, A. Chatzigeorgiou, S. Charalampidou, and P. Avgeriou. 2015. The Effect of GoF Design Patterns on Stability: A Case Study. IEEE Transactions on Software Engineering 41, 8 (Aug 2015), 781–802. DOI: Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Baeldung. 2016. Lambda Expressions and Functional Interfaces: Tips and Best Practices. (November 2016). http://www. baeldung.com/java-8-lambda-expressions-tipsGoogle ScholarGoogle Scholar
  4. Edd Barrett, Carl Friedrich Bolz-Tereick, Rebecca Killick, Sarah Mount, and Laurence Tratt. 2017. Virtual Machine Warmup Blows Hot and Cold. Proc. ACM Program. Lang. 1, OOPSLA (Oct. 2017).Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. James M. Bieman, Greg Straw, Huxia Wang, P. Willard Munger, and Roger T. Alexander. 2003. Design Patterns and Change Proneness: An Examination of Five Evolving Systems. In Proceedings of the 9th International Symposium on Software Metrics (METRICS ’03). 40–49. http://dl.acm.org/citation.cfm?id=942804.943777Google ScholarGoogle Scholar
  6. Joshua Bloch. 2008. Effective Java: A Programming Language Guide. Addison-Wesley Professional.Google ScholarGoogle Scholar
  7. Viviana Bono, Enrico Mensa, and Marco Naddeo. 2014. Trait-oriented programming in Java 8. In 2014 International Conference on Principles and Practices of Programming on the Java Platform Virtual Machines, Languages and Tools, PPPJ ’14, Cracow, Poland, September 23-26, 2014. 181–186. DOI: Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Virginia Braun and Victoria Clarke. 2006. Using thematic analysis in psychology. Qualitative Research in Psychology 3, 2 (2006), 77–101. DOI: Google ScholarGoogle ScholarCross RefCross Ref
  9. Ian Bull. 2014. Eclipse Support for Java 8. (March 2014). http://eclipsesource.com/blogs/2014/03/25/ eclipse-support-for-java-8/Google ScholarGoogle Scholar
  10. John L. Campbell, Charles Quincy, Jordan Osserman, and Ove K. Pedersen. 2013. Coding In-depth Semistructured Interviews. Sociological Methods & Research 42, 3 (2013), 294–320. DOI: Google ScholarGoogle ScholarCross RefCross Ref
  11. Alonzo Church. 1932. A Set of Postulates for the Foundation of Logic. Annals of Mathematics 33, 2 (1932), 346–366. http://www.jstor.org/stable/1968337 Google ScholarGoogle ScholarCross RefCross Ref
  12. Michael Coblenz, Joshua Sunshine, Jonathan Aldrich, Brad Myers, Sam Weber, and Forrest Shull. 2016. Exploring Language Support for Immutability. In Proceedings of the 38th International Conference on Software Engineering (ICSE ’16). 736–747. DOI: Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Diego Costa, Artur Andrzejak, Janos Seboek, and David Lo. 2017. Empirical Study of Usage and Performance of Java Collections. In Proceedings of the 8th ACM/SPEC on International Conference on Performance Engineering (ICPE ’17). 389–400. DOI: Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Daniela S. Cruzes and Tore Dybå. 2011. Research synthesis in software engineering: A tertiary study. Information and Software Technology 53, 5 (May 2011), 440–455. DOI: Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Anthony H. Dekker. 2006. Lazy Functional Programming in Java. SIGPLAN Notices 41, 3 (March 2006), 30–39. DOI: Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Eclipse Java development tools. 2017. JDT Components. (2017). http://www.eclipse.org/jdt/Google ScholarGoogle Scholar
  17. Robert Dyer, Hridesh Rajan, Hoan Anh Nguyen, and Tien N. Nguyen. 2014. Mining Billions of AST Nodes to Study Actual and Potential Usage of Java Language Features. In Proceedings of the 36th International Conference on Software Engineering (ICSE 2014). 779–790. DOI: Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Steve Easterbrook, Janice Singer, Margaret-Anne Storey, and Daniela Damian. 2008. Selecting Empirical Methods for Software Engineering Research. Springer London, 285–311. DOI: Google ScholarGoogle ScholarCross RefCross Ref
  19. Lukas Eder. 2014. jOOλ - The Missing Parts in Java 8. (2014). https://github.com/jOOQ/jOOLGoogle ScholarGoogle Scholar
  20. Lyle Franklin, Alex Gyori, Jan Lahoda, and Danny Dig. 2013. LAMBDAFICATOR: From Imperative to Functional Programming Through Automated Refactoring. In Proceedings of the 2013 International Conference on Software Engineering (ICSE ’13). 1287–1290. Google ScholarGoogle ScholarCross RefCross Ref
  21. Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. 1994. Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley Professional.Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Trisha Gee. 2015. Debugger Improvements. (November 2015). https://www.youtube.com/watch?v=rimzOolGguoGoogle ScholarGoogle Scholar
  23. Brian Goetz. 2012. Translation of Lambda Expressions. (April 2012). http://cr.openjdk.java.net/~briangoetz/lambda/ lambda-translation.htmlGoogle ScholarGoogle Scholar
  24. Alex Gyori, Lyle Franklin, Danny Dig, and Jan Lahoda. 2013. Crossing the gap from imperative to functional programming through refactoring. In ACM SIGSOFT Symposium on the Foundations of Software Engineering (ESEC/FSE). 543–553. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Jerry L. Hintze and Ray D. Nelson. 1998. Violin Plots: A Box Plot-Density Trace Synergism. The American Statistician 52, 2 (1998), 181–184.Google ScholarGoogle Scholar
  26. IntelliJ. 2017. Migrating to Java 8. (April 2017). https://www.jetbrains.com/help/idea/2017.1/migrating-to-java-8.htmlGoogle ScholarGoogle Scholar
  27. JavaParser. 2017. Java 9 Parser and Abstract Syntax Tree for Java. (2017). http://javaparser.org/Google ScholarGoogle Scholar
  28. Foutse Khomh and Yann-Gaël Guéhéneuc. 2008. Do Design Patterns Impact Software Quality Positively?. In 12th European Conference on Software Maintenance and Reengineering. 274–278. DOI: Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Sergey Kuksenko. 2013. JDK 8: Lambda Performance study. (2013). http://www.oracle.com/technetwork/java/ jvmls2013kuksen-2014088.pdfGoogle ScholarGoogle Scholar
  30. Henry B. Mann. 1945. Nonparametric Tests Against Trend. Econometrica 13, 3 (1945), 245–259. Google ScholarGoogle ScholarCross RefCross Ref
  31. Radu Marinescu. 2004. Detection Strategies: Metrics-Based Rules for Detecting Design Flaws. In Proceedings of the 20th IEEE International Conference on Software Maintenance (ICSM ’04). 350–359. Google ScholarGoogle ScholarCross RefCross Ref
  32. Davood Mazinanian, Ameya Ketkar, Nikolaos Tsantalis, and Danny Dig. 2017. Supplemental material. (2017). http: //dmazinanian.me/conference-papers/oopsla/2017/07/04/oopsla17.htmlGoogle ScholarGoogle Scholar
  33. Bartłomiej Mazur. 2017. Performance of Java, part 2. (2017). https://blog.gotofinal.com/java/benchmark/performance/2017/ 07/09/performance-of-java-1.htmlGoogle ScholarGoogle Scholar
  34. Erik Meijer and Sigbjorn Finne. 2001. Lambada, Haskell as a better Java. Electronic Notes in Theoretical Computer Science 41, 1 (2001), 91 – 119. DOI: Google ScholarGoogle ScholarCross RefCross Ref
  35. Emerson Murphy-Hill, Chris Parnin, and Andrew P. Black. 2009. How We Refactor, and How We Know It. In Proceedings of the 31st International Conference on Software Engineering (ICSE ’09). 287–297. DOI: Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. Emerson Murphy-Hill, Thomas Zimmermann, Christian Bird, and Nachiappan Nagappan. 2015. The Design Space of Bug Fixes and How Developers Navigate It. IEEE Transactions on Software Engineering 41, 1 (Jan 2015), 65–81. DOI: Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. T. H. Ng, S. C. Cheung, W. K. Chan, and Y. T. Yu. 2007. Do Maintainers Utilize Deployed Design Patterns Effectively?. In Proceedings of the 29th International Conference on Software Engineering (ICSE ’07). 168–177. DOI: Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. Adel Noureddine and Ajitha Rajan. 2015. Optimising Energy Consumption of Design Patterns. In Proceedings of the 37th International Conference on Software Engineering (ICSE ’15). 623–626. http://dl.acm.org/citation.cfm?id=2819009.2819120Google ScholarGoogle ScholarCross RefCross Ref
  39. Scott Oaks. 2014. Java Performance: The Definitive Guide: Getting the Most Out of Your Code. O’Reilly Media.Google ScholarGoogle Scholar
  40. Oracle. 2013. Java SE 8: Lambda Quick Start. (December 2013). http://www.oracle.com/webfolder/technetwork/tutorials/ obe/java/Lambda-QuickStart/index.htmlGoogle ScholarGoogle Scholar
  41. Oracle. 2014. Optional ( Java 8 Documentation). (2014). https://docs.oracle.com/javase/8/docs/api/java/util/Optional.htmlGoogle ScholarGoogle Scholar
  42. Oracle. 2015a. Lambda Expressions. (2015). https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.htmlGoogle ScholarGoogle Scholar
  43. Oracle. 2015b. Type Inference. (2015). https://docs.oracle.com/javase/tutorial/java/generics/genTypeInference.htmlGoogle ScholarGoogle Scholar
  44. V. Pankratius, F. Schmidt, and G. GarretÃşn. 2012. Combining functional and imperative programming for multicore software: An empirical study evaluating Scala and Java. In 2012 34th International Conference on Software Engineering (ICSE’12). 123–133. DOI: Google ScholarGoogle ScholarCross RefCross Ref
  45. Chris Parnin, Christian Bird, and Emerson Murphy-Hill. 2011. Java Generics Adoption: How New Features Are Introduced, Championed, or Ignored. In Proceedings of the 8th Working Conference on Mining Software Repositories (MSR ’11). 3–12. DOI: Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. L. Prechelt, B. Unger, W. F. Tichy, P. Brössler, and L. G. Votta. 2001. A Controlled Experiment in Maintenance Comparing Design Patterns to Simpler Solutions. IEEE Transactions on Software Engineering 27, 12 (Dec. 2001), 1134–1144. DOI: Google ScholarGoogle ScholarDigital LibraryDigital Library
  47. Eric S. Raymond. 2001. The Cathedral and the Bazaar: Musings on Linux and Open Source by an Accidental Revolutionary. O’Reilly & Associates, Inc., Sebastopol, CA, USA.Google ScholarGoogle Scholar
  48. Romain Robbes, David Röthlisberger, and Éric Tanter. 2015. Object-oriented software extensions in practice. Empirical Software Engineering 20, 3 (2015), 745–782. DOI: Google ScholarGoogle ScholarDigital LibraryDigital Library
  49. Nathanael Schärli, Stéphane Ducasse, Oscar Nierstrasz, and Andrew P. Black. 2003. Traits: Composable Units of Behaviour. In Proceedings of the 17th European Conference on Object-Oriented Programming (ECOOP’03). 248–274. DOI: Google ScholarGoogle ScholarCross RefCross Ref
  50. Pranab Kumar Sen. 1968. Estimates of the Regression Coefficient Based on Kendall’s Tau. J. Amer. Statist. Assoc. 63, 324 (1968), 1379–1389. Google ScholarGoogle ScholarCross RefCross Ref
  51. Anton Setzer. 2003. Java as a Functional Programming Language. In : International Workshop of Types for Proofs and Programs (TYPES 2002). 279–298. DOI: Google ScholarGoogle ScholarCross RefCross Ref
  52. Danilo Silva, Nikolaos Tsantalis, and Marco Tulio Valente. 2016. Why We Refactor? Confessions of GitHub Contributors. In Proceedings of the 2016 24th ACM SIGSOFT International Symposium on Foundations of Software Engineering (FSE 2016). 858–870. DOI: Google ScholarGoogle ScholarDigital LibraryDigital Library
  53. Janice Singer, Susan E. Sim, and Timothy C. Lethbridge. 2008. Software Engineering Data Collection for Field Studies. In Guide to Advanced Empirical Software Engineering, Forrest Shull, Janice Singer, and Dag I. K. Sjøberg (Eds.). Springer London, Chapter 1, 9–34. Google ScholarGoogle ScholarCross RefCross Ref
  54. Ewan Tempero, Hong Yul Yang, and James Noble. 2013. What Programmers Do with Inheritance in Java. In Proceedings of the 27th European Conference on Object-Oriented Programming (ECOOP 2013). 577–601. DOI: Google ScholarGoogle ScholarDigital LibraryDigital Library
  55. TouK. 2017. ThrowingFunction. (2017). https://github.com/TouK/ThrowingFunctionGoogle ScholarGoogle Scholar
  56. Nikolaos Tsantalis, Davood Mazinanian, and Giri P. Krishnan. 2015. Assessing the Refactorability of Software Clones. IEEE Transactions on Software Engineering 41, 11 (Nov 2015), 1055–1090. DOI: Google ScholarGoogle ScholarDigital LibraryDigital Library
  57. Nikolaos Tsantalis, Davood Mazinanian, and Shahriar Rostami. 2017. Clone Refactoring with Lambda Expressions. In Proceedings of the 39th International Conference on Software Engineering (ICSE ’17). 60–70. DOI: Google ScholarGoogle ScholarDigital LibraryDigital Library
  58. Phillip Merlin Uesbeck, Andreas Stefik, Stefan Hanenberg, Jan Pedersen, and Patrick Daleiden. 2016. An Empirical Study on the Impact of C++ Lambdas and Programmer Experience. In Proceedings of the 38th International Conference on Software Engineering (ICSE ’16). 760–771. DOI: Google ScholarGoogle ScholarDigital LibraryDigital Library
  59. Marek Vokáč, Walter Tichy, Dag I. K. Sjøberg, Erik Arisholm, and Magne Aldrin. 2004. A Controlled Experiment Comparing the Maintainability of Programs Designed with and Without Design Patterns – A Replication in a Real Programming Environment. Empirical Software Engineering 9, 3 (Sept. 2004), 149–195. DOI: Google ScholarGoogle ScholarDigital LibraryDigital Library
  60. Geertjan Wielenga. 2014. Smart Migration to JDK 8 in NetBeans IDE. (January 2014). https://netbeans.org/kb/docs/java/ jdk8-migration-screencast.htmlGoogle ScholarGoogle Scholar
  61. Claes Wohlin and Aybüke Aurum. 2015. Towards a decision-making structure for selecting a research design in empirical software engineering. Empirical Software Engineering 20, 6 (2015), 1427–1455. DOI: Google ScholarGoogle ScholarDigital LibraryDigital Library
  62. Alex Zhitnitsky. 2015. Benchmark: How Misusing Streams Can Make Your Code 5 Times Slower. (2015). http://blog.takipi. com/benchmark-how-java-8-lambdas-and-streams-can-make-your-code-5-times-slower/Google ScholarGoogle Scholar

Index Terms

  1. Understanding the use of lambda expressions in Java

          Recommendations

          Comments

          Login options

          Check if you have access through your login credentials or your institution to get full access on this article.

          Sign in

          Full Access

          PDF Format

          View or Download as a PDF file.

          PDF

          eReader

          View online with eReader.

          eReader
          About Cookies On This Site

          We use cookies to ensure that we give you the best experience on our website.

          Learn more

          Got it!