一句话:通过209名开发者的对照实验,评估Python函数式构造相比过程式写法在可理解性上的差异与使用建议。
论文关注 Python 中函数式构造(lambda、推导式、map/reduce/filter)是否比过程式写法更难理解。作者开展有 209 名开发者参与的对照实验,要求参与者修改使用/不使用函数式构造的代码,比较不同实现的可理解性,并收集关于何时何地适合使用这些构造的看法。结果发现:含 lambda 的代码片段比过程式替代更易修改,但推导式并非如此;在主观可理解性上,过程式实现被认为比函数式替代更可读。此外,函数式构造虽可写出紧凑代码、有助于可维护性和性能,但被认为难以调试。结论可为函数式构造的教学、质量保证活动优先级和工具支持提供依据。
The use of functional constructs in programming languages such as Python has been advocated to help write more concise source code, improve parallelization, and reduce side effects. Nevertheless, their usage could lead to understandability issues. This paper reports the results of a controlled experiment conducted with 209 developers to assess the understandability of given Pythonic functional constructs---namely lambdas, comprehensions, and map/reduce/-filter functions---if compared to their procedural alternatives. To address the study's goal, we asked developers to modify code using functional constructs or not, to compare the understandability of different implementations, and to provide insights about when and where it is preferable to use such functional constructs. Results of the study indicate that code snippets with lambdas are more straightforward to modify than the procedural alternatives. However, this is not the case for comprehension. Regarding the perceived understandability, code snippets relying on procedural implementations are considered more readable than their functional alternatives. Last but not least, while functional constructs may help write compact code, improving maintainability and performance, they are considered hard to debug. Our results can lead to better education in using functional constructs, prioritizing quality assurance activities, and enhancing tool support for developers.
@inproceedings{paperbot11391,
title = {A Study on the Pythonic Functional Constructs' Understandability},
author = {Cyrine Zid and Fiorella Zampetti and Giuliano Antoniol and Massimiliano Di Penta},
booktitle = {ICSE},
year = {2024},
doi = {10.1145/3597503.3639211}
}