Abstract
Lambda expressions have long been state-of-the-art in the functional programming paradigm. Especially with regard to the use of higher-order functions, they provide developers with a means of defining predicate or projection functions locally, which greatly increases the comprehensibility of the resulting source code. This benefit has motivated language designers to also incorporate lambda expressions into object-oriented (OO) programming languages. In particular, they are claimed to facilitate concurrent programming. One likely reason for this assumption is their purity: pure lambda expressions are free of side effects, and therefore cannot cause, e.g., race conditions. In this paper, we present the first empirical analysis of whether or not this claim is true for OO projects. For this purpose, we investigated the application of lambda expressions in 2923 open-source projects, implemented in one of the most common OO programming languages: C#, C++, and Java. We present three major findings. First, the majority of lambda expressions are not applied in concurrent code and most concurrent code does not make use of lambda expressions. Second, for all three of the languages, we observed that developers compromise their code by applying a significantly higher number of impure, capturing lambda expressions, which are capable of causing race conditions. Finally, we explored further use cases of lambda expressions and found out that testing, algorithmic implementation, and UI are far more common use-cases for the application of lambda expressions. Our results encourage to investigate in more detail the reasons that hinder programmers to apply lambda expressions in concurrent programming and to support developers, e.g., by providing automatic refactorings.




















Similar content being viewed by others
Notes
Sometimes they are also referred to as the overall concept of closures.
TIOBE Index January’16, RedMonk Programming Language Ranking January’16, PYPL PopularitY of Programming Language January’16
C# used delegates since its first version, which represent a kind of function pointers
A variable is called effectively final if there is no further write access to this variable after its initialization.
The same behavior can be achieved by assigning the variable i to an effectively final local variable in the loop’s body and capture this value in the lambda expression
The grammar is available at https://github.com/antlr/grammars-v4/tree/master/csharp
February 5th, 2018
References
Barr M (1999) Programming embedded systems in C and C++. O’Reilly Media, Inc, Sebastopol
Bavota G, Gethers M, Oliveto R, Poshyvanyk D, de Lucia A (2014) Improving software modularization via automated analysis of latent topics and dependencies. ACM Trans Softw Eng Methodol (TOSEM) 23(1):4:1–4:33. https://doi.org/10.1145/2559935
Ben-Ari M (2006) Principles of concurrent and distributed programming, 2nd edn. Pearson Education Limited, England
Borges H, Hora A, Valente MT (2016) Understanding the factors that impact the popularity of GitHub repositories. In: Proceedings of the 32nd IEEE international conference on software maintenance and evolution (ICSME). IEEE, pp 334–344. https://doi.org/10.1109/ICSME.2016.31
Coblenz M, Sunshine J, Aldrich J, Myers B, Weber S, Shull F (2016) Exploring language support for immutability. In: Proceedings of the 38th international conference on software engineering (ICSE). ACM, New York, pp 736–747. https://doi.org/10.1145/2884781.2884798
Coblenz M, Nelson W, Aldrich J, Myers B, Sunshine J (2017) Glacier: transitive class immutability for java. In: Proceedings of the 39th international conference of software engineering (ICSE). IEEE Press, Piscataway, pp 496–506. https://doi.org/10.1109/ICSE.2017.52
Costa D, Andrzejak A, Seboek J, Lo D (2017) Empirical study of usage and performance of java collections. In: Proceedings of the 8th ACM/SPEC on international conference on performance engineering (ICPE). ACM, New York, pp 389–400. https://doi.org/10.1145/3030207.3030221
De Wael M, Marr S, Van Cutsem T (2014) Fork/join parallelism in the wild: documenting patterns and anti-patterns in java programs using the fork/join framework. In: Proceedings of the 11th international conference on principles and practices of programming on the java platform: virtual machines, languages, and tools (PPPJ). ACM, New York, pp 39–50. https://doi.org/10.1145/2647508.2647511
Dekker AH (2006) Lazy functional programming in java. ACM SIGPLAN Not 41(3):30–39. https://doi.org/10.1145/1140543.1140549
Dyer R, Rajan H, Nguyen HA, Nguyen TN (2013) A large-scale empirical study of java language feature usage. Tech. rep., Iowa State University. https://lib.dr.iastate.edu/cs_techreports/289/
Dyer R, Rajan H, Nguyen HA, Nguyen TN (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). ACM, New York, pp 779–790. https://doi.org/10.1145/2568225.2568295
Dyer R, Nguyen HA, Rajan H, Nguyen TN (2015) Boa: ultra-large-scale software repository and source-code mining. ACM Trans Softw Eng Methodol 25(1):7:1–7:34
Franklin L, Gyori A, Lahoda J, Dig D (2013) LAMBDAFICATOR: from imperative to functional programming through automated refactoring. In: Proceedings of the 35th international conference on software engineering (ICSE). IEEE Press, Piscataway, pp 1287–1290. http://dl.acm.org/citation.cfm?id=2486788.2486986
Garcia R, Jarvi J, Lumsdaine A, Siek JG, Willcock J (2003) A comparative study of language support for generic programming. In: Proceedings of the 18th annual ACM SIGPLAN conference on object-oriented programming, systems, languages, and applications (OOPSLA), pp 115–134
Gu R, Jin G, Song L, Zhu L, Lu S (2015) What change history tells us about thread synchronization. In: Proceedings of the 10th joint meeting of the european software engineering conference and the ACM SIGSOFT symposium on the foundations of software engineering (ESEC/FSE). ACM, New York, pp 426–438. https://doi.org/10.1145/2786805.2786815
Gyori A, Franklin L, Dig D, Lahoda J (2013) Crossing the gap from imperative to functional programming through refactoring. In: Proceedings of the 9th joint meeting of the European software engineering conference and the ACM SIGSOFT symposium on the foundations of software engineering (ESEC/FSE). ACM, pp 543–553
Hill E, Pollock L, Vijay-Shanker K (2009) Automatically capturing source code context of NL-queries for software maintenance and reuse. In: Proceedings of the 31st international conference on software engineering (ICSE). IEEE, pp 232–242
Jarczyk O, Gruszka B, Jaroszewicz S, Bukowski L, Wierzbicki A (2014) GitHub projects. quality analysis of open-source software. In: Aiello LM, McFarland D (eds) Proceedings of the 6th international conference on social informatics (SocInfo). Springer International Publishing, Cham, pp 80–94. https://doi.org/10.1007/978-3-319-13734-6_6
Järvi J, Freeman J (2010) C++ lambda expressions and closures. Sci Comput Program 75(9):762–772
Kim D, Murphy-Hill E, Parnin C, Bird C, Garcia R (2013) The reaction of open-source projects to new language features: an empirical study of C# generics. Journal of Object Technology 12(4):1:1–1:31
Kuhn A, Ducasse S, Gîrba T (2007) Semantic clustering: identifying topics in source code. Inf Softw Technol 49(3):230–243. https://doi.org/10.1016/j.infsof.2006.10.017. http://www.sciencedirect.com/science/article/pii/S0950584906001820. 12th Working Conference on Reverse Engineering
Lin Y, Dig D (2013) Check-then-act misuse of java concurrent collections. In: Proceedings of the 6th international conference on software testing, verification and validation (ICST). IEEE, pp 164–173
Lin Y, Radoi C, Dig D (2014) Retrofitting concurrency for android applications through refactoring. In: Proceedings of the 22nd ACM SIGSOFT international symposium on foundations of software engineering (FSE). ACM, New York, pp 341–352. https://doi.org/10.1145/2635868.2635903
Marinescu C (2014) An empirical investigation on MPI open source applications. In: Proceedings of the 18th international conference on evaluation and assessment in software engineering (EASE). ACM, New York, pp 20:1–20:4. https://doi.org/10.1145/2601248.2601298
Martelli A, Ravenscroft A, Ascher D (eds) (2005) Python cookbook, vol 2. O’Reilly Media Inc, Sebastopol
Mazinanian D, Ketkar A, Tsantalis N, Dig D (2017) Understanding the use of lambda expressions in java. Proceedings of the ACM on Programming Languages 1 (OOPSLA):85:1–85:31. https://doi.org/10.1145/3133909
Meijer E, Finne S (2001) Lambada, Haskell as a better Java. Electron Notes Theor Comput Sci 41(1):91–119. https://doi.org/10.1016/S1571-0661(05)80549-3. http://www.sciencedirect.com/science/article/pii/S1571066105805493. 2000 ACM SIGPLAN Haskell Workshop (Satellite Event of PLI 2000)
Miller W, Myers EW (1985) A file comparison program. Software: Practice and Experience 15(11):1025–1040
Myers EW (1986) An O(ND) difference algorithm and its variations. Algorithmica 1(1–4):251–266
Odersky M, Rompf T (2014) Unifying functional and object-oriented programming with scala. Commun ACM 57(4):76–86. https://doi.org/10.1145/2591013
Okur S, Dig D (2012) How do developers use parallel libraries?. In: Proceedings of the ACM SIGSOFT 20th international symposium on the foundations of software engineering (FSE). ACM, New York, pp 54:1–54:11. https://doi.org/10.1145/2393596.2393660
Okur S, Hartveld DL, Dig D, van Deursen A (2014) A study and toolkit for asynchronous programming in C#. In: Proceedings of the 36th international conference on software engineering (ICSE). ACM, New York, pp 1117–1127. https://doi.org/10.1145/2568225.2568309
Pankratius V, Schmidt F, Garretón G (2012) Combining functional and imperative programming for multicore software: an empirical study evaluating scala and java. In: Proceedings of the 34th international conference on software engineering (ICSE). IEEE Press, Piscataway, pp 123–133. http://dl.acm.org/citation.cfm?id=2337223.2337238
Parnin C, Bird C, Murphy-Hill E (2011) Java generics adoption: how new features are introduced, championed, or ignored. In: Proceedings of the 8th working conference on mining software repositories (MSR). ACM, pp 3–12
Parnin C, Bird C, Murphy-Hill E (2013) Adoption and use of java generics. Empir Softw Eng (EMSE) 18(6):1047–1089
Parr T (2013) The definitive ANTLR 4 reference, 2nd edn. The Pragmatic Programmers, Raleigh
Pinto G, Torres W, Fernandes B, Castor F, Barros RS (2015) A large-scale study on the usage of java’s concurrent programming constructs. J Syst Softw 106(Supplement C):59–81. https://doi.org/10.1016/j.jss.2015.04.064. http://www.sciencedirect.com/science/article/pii/S0164121215000849
Radoi C, Dig D (2013) Practical static race detection for java parallel loops. In: Proceedings of the 22nd international symposium on software testing and analysis (ISSTA). ACM, New York, pp 178–190. https://doi.org/10.1145/2483760.2483765
Stefik A, Hanenberg S (2014) The programming language wars: questions and responsibilities for the programming language community. In: Proceedings of the 13th ACM international symposium on new ideas, new paradigms, and reflections on programming & software (Onward!). ACM, pp 283–299
Tempero E, Yang HY, Noble J (2013) What programmers do with inheritance in java. In: Castagna G (ed) Proceedings of the 27th European conference object-oriented programming (ECOOP). Springer Berlin Heidelberg, Berlin, Heidelberg, pp 577–601. https://doi.org/10.1007/978-3-642-39038-8_24
Torres W, Pinto G, Fernandes B, Oliveira JP, Ximenes FA, Castor F (2011) Are java programmers transitioning to multicore?: a large scale study of java FLOSS. In: Proceedings of the compilation of the co-located workshops on DSM’11, TMC’11, AGERE! 2011, AOOPES’11, NEAT’11, & VMIL’11. ACM, New York, pp 123–128. https://doi.org/10.1145/2095050.2095072
Tsantalis N, Mazinanian D, Rostami S (2017) Clone refactoring with lambda expressions. In: Proceedings of the 39th international conference on software engineering (ICSE). IEEE Press, Piscataway, pp 60–70. https://doi.org/10.1109/ICSE.2017.14
Uesbeck PM, Stefik A, Hanenberg S, Pedersen J, Daleiden P (2016) An empirical study on the Impact of C++ lambdas and programmer experience. In: Proceedings of the 38th international conference on software engineering (ICSE). ACM, pp 760–771
Ukkonen E (1985) Algorithms for approximate String Matching. Inf Control 64 (1–3):100–118
Wang X, Pollock L, Vijay-Shanker K (2017) Automatically generating natural language descriptions for object-related statement sequences. In: Proceedings of the 24th international conference on software analysis, evolution and reengineering (SANER). IEEE, pp 205–216
Wu D, Chen L, Zhou Y, Xu B (2016) An extensive empirical study on C++ concurrency constructs. Inf Softw Technol 76(Supplement C):1–18. https://doi.org/10.1016/j.infsof.2016.04.004. http://www.sciencedirect.com/science/article/pii/S0950584916300581
Author information
Authors and Affiliations
Corresponding author
Additional information
Communicated by: Emerson Murphy-Hill
Rights and permissions
About this article
Cite this article
Nielebock, S., Heumüller, R. & Ortmeier, F. Programmers do not favor lambda expressions for concurrent object-oriented code. Empir Software Eng 24, 103–138 (2019). https://doi.org/10.1007/s10664-018-9622-9
Published:
Issue Date:
DOI: https://doi.org/10.1007/s10664-018-9622-9