paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Imperative versus declarative collection processing

命令式与声明式集合处理
ICSE Proceedings of the 44th International Conference on Software Engineering2022匹配度 1/10 · 该论文研究 Java Stream API 与循环在集合操作上的可理解性,属于编程语言可用性/实证软件工程,与用户关注的静态分析、LLM/Agent 结合、浮点程序分析和贝叶斯程序分析均无直接关联。引用 4 inbox
Nils Mehlhorn, Stefan Hanenberg
crossref: 2026-09-12

AI 速览

一句话:随机对照实验表明,Java Stream API 的声明式集合代码在理解速度与正确性上显著优于传统循环。

Java 8 引入的 Stream API 允许以声明式风格、借助 lambda 表达式处理集合,但该 API 相比传统命令式循环在可用性上是否更优尚不明确。本文针对集合操作的可理解性开展随机对照实验(RCT),20 名参与者需判断分别用 Stream API 或循环定义的集合操作的结果,因变量为响应时间与正确性。结果显示:Stream API 对响应时间有显著(p<.001)且大的正向效应,使用 Stream API 时错误显著更少;参与者还自评使用 Stream API 时速度更快,并认为基于 Stream API 的代码更易读。与以往发现声明式构造(lambda 表达式)对主流语言可用性有负面影响的研究不同,本研究表明基于 lambda 的 Stream API 声明式集合代码相较传统循环具有显著的正向效果。

问题
Java 8 的 Stream API 提供了声明式集合处理方式,但其相比传统循环是否在可用性(尤其是代码可理解性)上更优尚不清楚。
方法
开展随机对照实验(RCT),20 名参与者完成集合操作结果判断任务,操作分别用 Stream API 或循环定义,测量响应时间与正确性,并收集主观感知。
评估
统计分析显示 Stream API 对响应时间有显著且大的正向效应(p<.001),错误显著更少;参与者主观认为 Stream API 速度更快、代码更易读,与以往关于声明式构造的负面结论相反。
原文摘要(Abstract)

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 is beneficial in comparison to loops in terms of usability is unclear. The present paper introduces a randomized control trial (RCT) on the understandability of collection operations performed on 20 participants with the dependent variables response time and correctness. 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 [EQUATION] 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 readable. 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.

链接与引用

DOI 原文 ·

BibTeX
@inproceedings{paperbot6923,
  title = {Imperative versus declarative collection processing},
  author = {Nils Mehlhorn and Stefan Hanenberg},
  booktitle = {ICSE},
  year = {2022},
  doi = {10.1145/3510003.3519016}
}