Programmers do not Favor Lambda Expressions for Concurrent ... · Functional elements in...
Transcript of Programmers do not Favor Lambda Expressions for Concurrent ... · Functional elements in...
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
• 𝑢𝑡𝑖𝑙𝑖𝑧𝑎𝑡𝑖𝑜𝑛 𝑝 =𝑛𝑢𝑚𝑏𝑒𝑟𝐹𝑖𝑙𝑒𝑠𝑊𝑖𝑡ℎ𝐿𝑎𝑚𝑏𝑑𝑎𝐼𝑛𝐶𝑜𝑛𝑐𝐶𝑜𝑛𝑡𝑒𝑥𝑡(𝑝)
𝑛𝑢𝑚𝑏𝑒𝑟𝐹𝑖𝑙𝑒𝑠𝑊𝑖𝑡ℎ𝐶𝑜𝑛𝑐𝐶𝑜𝑛𝑡𝑒𝑥𝑡(𝑝)
Results Frequency II
*only 1399 projectsthat use concurrentcontexts andlambda expressions
Slide 11 / 07.11.2018 Chair of Software Engineering
Results - Capturing Lambda Expressions
Slide 12 / 07.11.2018 Chair of Software Engineering
Results – Other Use Cases
Slide 13 / 07.11.2018 Chair of Software Engineering
• Higher intensity/utilization in C# Refactoring mechanisms for other programming languages
• Capturing lambda expressions as a diminishing factor Detect/Repair Misuses of the functional programming API in OO-
languages
Other problems?
• Other use cases as testing and algorithmics automatic refactorings for these use cases?
Implications
Slide 14 / 07.11.2018 Chair of Software Engineering
Thank you for your attention!
Sebastian Nielebock
Mail: [email protected]
Web: https://cse.cs.ovgu.de/cse/members/sebastian-nielebock/
Replication of our results:
http://dx.doi.org/10.1007/s10664-018-9622-9
https://bitbucket.org/SNielebock/lambdainconcurrentdataset
Appendix
Slide 16 / 07.11.2018 Chair of Software Engineering
atomic
concurrent
future
parallel
runnable
sync
thread
Concurrency Keywords
Slide 17 / 07.11.2018 Chair of Software Engineering
Use Case Keywords
Algorithmic - Implementation of an Algorithm
algorithm, calc, search, script, analyze, util, helper, manager, cluster, generate, generation, generator, optimize,optimization, visitor, process, select, service, factory, provider, operate, operation, operator, find, tracker, mutation, mutate, mutator, compute, backend, sort
Composition - Composition or Decomposition of Data
composition, spawn, multiplexer, serializer, compose, split, join, build, combine, combinator
Configuration - Configuration of the Software
config, setting, info, readme, version, option, default
DataStorage – Database Actions data, storage, cache, sql, query, queries
Datastructure - Implementation of Data Structures
array, list, map, tree, string, object, graph, heap, stack, table, queue, node, template, matrix, vector, collect, set, item, unit, type, entity, enum, container, element, model
Use Cases Keywords I
Slide 18 / 07.11.2018 Chair of Software Engineering
Use Case Keywords
Embedded Programming hardware, camera, keyboard, mouse, memory, embedded, device, cpu, x86, x64
ExceptionHandling exception, error, warn, crash, bug, check, undefined
FileHandling file, directory, writer, reader
Graphical – visualization and graphical elements
graphical, color, pixel, gpu, render, light, texture, image, picture, shadow, draw, animation, animate, fade, geometry, point, scene, line, polygon, square, rectangle, circle, shape, visualisize, visualizer, ellipse, paint
Logging log
MultiMedia - video or audio management
audio, video, media, player, touch, virtual, recognize, gesture, codec
MultiThreading – parallel or concurrent implementation
thread, parallel, concurrent, sync, block, schedule, wait, handle, runtime, semaphore, event, signal, task, callback, callable, dispatch, mutex, suspend, job, sleep, timer
Use Cases Keywords II
Slide 19 / 07.11.2018 Chair of Software Engineering
Use Case Keywords
Network - web application net, server, client, remote, middleman, http, chat, distributed, delegate, request, timeout, message, share, sharing, socket, connect, receive, send, traffic, cookie, connection, cloud, ping, session, download, web, host, url, dns
Security security, authenticate, authentication, account, crypt
Test - automatic softwaretesting
test, benchmark, assert
TextManagement – textprocessing applications
string, character, document, parser, parse, csv, json, xml, scan, format, translation, translate, encoding, encode, decoding, decode, utf8, ascii, word
UI - user interface gui, widget, view, shell, display, button, canvas, editor, console, popup, bar, frame, scrollbar, window, about, listener, menu, command, action, layout, box, frontend
Use Cases Keywords III
Slide 20 / 07.11.2018 Chair of Software Engineering
Overview Projects with Lambda
Slide 21 / 07.11.2018 Chair of Software Engineering
Overview Projects with Concurrency
Slide 22 / 07.11.2018 Chair of Software Engineering
Overview Projects with Lambda and Conc.
Slide 23 / 07.11.2018 Chair of Software Engineering
Utilization – Projects with Concurrency
Slide 24 / 07.11.2018 Chair of Software Engineering
Use Cases C#
Slide 25 / 07.11.2018 Chair of Software Engineering
Use Cases C++
Slide 26 / 07.11.2018 Chair of Software Engineering
Use Cases Comparison