一句话:首个大规模实证研究,归纳 Java 中 lambda 被移除的七类原因与七种迁移模式,并给出实践建议。
Java 8 引入 lambda 表达式后,其在项目中的采用率持续上升,开发者常用它简化代码、消除重复或模拟函数式特性。然而 lambda 也可能带来性能问题、内存泄漏甚至严重缺陷,实践中开发者频繁移除已写下的 lambda,使其收益被副作用抵消。本文开展首个大规模定量与定性实证研究,系统刻画 Java 中 lambda 表达式的不当使用:作者从代码仓库中挖掘 lambda 移除的相关变更,归纳出七类主要移除原因与七种常见迁移模式,例如使用自定义函数式接口的 lambda 更容易被移除。作为补充,作者还对 30 名开发者进行用户研究,探究其在实践中移除 lambda 的真实动机。基于实证结果,论文为 Java 开发者指出应避免使用 lambda 的场景,并为研究者提出后续方向。
Java 8 has introduced lambda expressions, a core feature of functional programming. Since its introduction, there is an increasing trend of lambda adoptions in Java projects. Developers often adopt lambda expressions to simplify code, avoid code duplication or simulate other functional features. However, we observe that lambda expressions can also incur different types of side effects (i.e., performance issues and memory leakages) or even severe bugs, and developers also frequently remove lambda expressions in their implementations. Consequently, the advantages of utilizing lambda expressions can be significantly compromised by the collateral side effects. In this study, we present the first large-scale, quantitative and qualitative empirical study to characterize and understand inappropriate usages of lambda expressions. Particularly, we summarized seven main reasons for the removal of lambdas as well as seven common migration patterns. For instance, we observe that lambdas using customized functional interfaces are more likely to be removed by developers. Moreover, from a complementary perspective, we performed a user study over 30 developers to seek the underlying reasons why they remove lambda expressions in practice. Finally, based on our empirical results, we made suggestions on scenarios to avoid lambda usages for Java developers and also pointed out future directions for researchers.
DOI 原文 ·
@inproceedings{paperbot6639,
title = {Why Do Developers Remove Lambda Expressions in Java?},
author = {Mingwei Zheng and Jun Yang and Ming Wen and Hengcheng Zhu and Yepang Liu and Hai Jin},
booktitle = {ASE},
year = {2021},
doi = {10.1109/ase51524.2021.9678600}
}