Otto-von-Guericke University Magdeburg, Germany Chair of Software Engineering November 6 th , 2018 26th ACM Joint European Software Engineering Conference and Symposium on the Foundations of Software Engineering (ESEC/FSE), Lake Buena Vista, Florida, USA Programmers do not Favor Lambda Expressions for Concurrent Object-Oriented Code Sebastian Nielebock Robert Heumüller Frank Ortmeier
26
Embed
Programmers do not Favor Lambda Expressions for Concurrent ... · Functional elements in OO-languages: Java 8 (Lambda expressions and streams) •Simpler programming Defining and
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Otto-von-Guericke University Magdeburg, GermanyChair of Software Engineering
November 6th, 201826th ACM Joint European Software Engineering Conference and Symposium on the Foundations of
Software Engineering (ESEC/FSE), Lake Buena Vista, Florida, USA
Programmers do not Favor Lambda Expressions for Concurrent Object-Oriented
Code
Sebastian Nielebock Robert Heumüller Frank Ortmeier
Slide 2 / 07.11.2018 Chair of Software Engineering
• Trend of incorporation of functional elements Multi-paradigm languages: Scala, Python
Functional elements in OO-languages: Java 8 (Lambda expressions and streams)
• Simpler programming Defining and combining simple functions
Pure programming = no side effects/context information
immutability
More concise code:A Comparative Study of Programming Languages in Rosetta Code –
ICSE’15 - S. Nanz and C. A. Furia
Functional Programming in other Languages
Slide 3 / 07.11.2018 Chair of Software Engineering
• Anonymous functions with simple local functionality
• Incorporated by most major OO-programming languages• C# - since C# 3.0 in 2007
• C++ - since C++11 in 2011
• Java - since Java 8 since 2014
Lambda Expressions
public static void main(String... args){
int[] numbersArray = {0,1,2,3,4,5,6,7,8,9,10};
Arrays.stream(numbersArray)
.filter(n -> n%2==0).map(en -> 3*en+1)
.forEach(System.out::println);
}
Slide 4 / 07.11.2018 Chair of Software Engineering
• Concurrency ≠ Parallelism (Talk by Rob Pike) Code that can potentially run in parallel
• Benefits less boilerplate code
original lambda expressions do not introduce side effects
Lambda expressions facilitate concurrent development
Lambda Expressions in Concurrent Code
Slide 5 / 07.11.2018 Chair of Software Engineering
• Facilitation hardly measurable
• Frequency as an indicator of facilitation 𝐹𝑎𝑐𝑖𝑙𝑖𝑡𝑎𝑡𝑖𝑜𝑛 → 𝐹𝑟𝑒𝑞𝑢𝑒𝑛𝑐𝑦
• Low frequency either no facilitation or
another diminishing factor
Measurement
Slide 6 / 07.11.2018 Chair of Software Engineering
= Lambda expressions using outer context in their bodies
• Problems in concurrent programming:
Capturing Lambda Expressions/Closures
for (int i = 0; i < 10; i++)
{
new Thread(
() => Console.Write(i + " ")).Start();
}
// output: 4 4 4 4 5 7 9 9 9 10
for (int i = 0; i < 10; i++)
{
new Thread(
value => Console.Write(value + " ")).Start(i);
}
// output: 0 1 3 2 4 6 5 7 8 9
Slide 7 / 07.11.2018 Chair of Software Engineering
1. Frequency of lambda expressions in concurrent contexts• Differences between C#, C++, Java
2. Ratio of capturing to non-capturing lambda in concurrency
3. Other use cases apart from concurrency
Research Questions
Slide 8 / 07.11.2018 Chair of Software Engineering
Study
Project Selection
GitHub Stars
ParsingCode
ANTLR parser, CDT, JDT
ConcurrentContext
Lambda Expression
• Analysis ofimports andparent nodeswith keywords
Files
Use Cases
• AST-node types• Capturing
lambdas: Analysis for non-local variables
• Semi-automaticfile name mapping
1000 projects for eachprogramming language in
C#, C++, and Java
2923 projects
Slide 9 / 07.11.2018 Chair of Software Engineering
• 𝑖𝑛𝑡𝑒𝑛𝑠𝑖𝑡𝑦 𝑝 =𝑛𝑢𝑚𝑏𝑒𝑟𝐿𝑎𝑚𝑏𝑑𝑎𝐼𝑛𝐶𝑜𝑛𝑐𝐶𝑜𝑛𝑡𝑒𝑥𝑡(𝑝)
𝑛𝑢𝑚𝑏𝑒𝑟𝐿𝑎𝑚𝑏𝑑𝑎(𝑝)
Results Frequency I
*only 1597 projectsthat use lambdaexpressions
Slide 10 / 07.11.2018 Chair of Software Engineering