Imperative versus Declarative Collection Processing: An RCT on the Understandability of Traditional Loops versus the Stream API in Java
Thu 12 May 2022 04:25 - 04:30 at ICSE room 5-even hours - Programming Languages 1 Chair(s): Jean-Guy Schneider
Java introduced in version 8 with the Stream API means to operate on collections using lambda expressions. Since then, this API is an alternative way to handle collections in a more declarative manner instead of the traditional, imperative style using loops. However, whether the Stream API in comparison to loops is beneficial in terms of usability is unclear. The present paper introduces a randomized control trial (RCT) on the understandability of collection operations with the dependent variables response time and correctness performed on 20 participants. As tasks, subjects had to determine the results for collection operations (either defined with the Stream API or with loops). The results indicate that the Stream API has a significant (p<.001) and large (η²=.695; M(loop)/{M(stream)=178%) positive effect on the response times. Furthermore, the usage of the Stream API caused significantly less errors. And finally, the participants perceived their speed with the Stream API higher compared to the loop-based code and the participants considered the code based on the Stream API as more aesthetic. Hence, while existing studies found a negative effect of declarative constructs (in terms of lambda expressions) on the usability of a main stream programming language, the present study found the opposite: the present study gives evidence that declarative code on collections using the Stream API based on lambda expressions has a large, positive effect in comparison to traditional loops.